![]() |
Crash in CXTPControls::RefreshIndexes() |
Post Reply
|
| Author | |
jhuckins
Newbie
Joined: 17 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Topic: Crash in CXTPControls::RefreshIndexes()Posted: 17 September 2007 at 4:32pm |
|
I had submitted a problem I was having with XTreme Toolkit Pro v9.70 earlier today, but now I have v11.2.0 installed and am having essentially the same problem, just with slightly different results.
The scenario is that a CXTPFrameWnd derived report window is closing. This report window has a lot of XTP controls, menubars, etc associated with it. It appears that during control cleanup in the call to CXTPControls::RemoveAll(), the CXTPControls object comes across a control in the list that is no longer valid since it's vtable appears to be gone, so as soon as an attempt is made down in CXTPControls::RefreshIndexes() to invoke the SetParent() method on the control object, an exception is thrown and CObject::DumpContext() invoked. The control that it crashes on appears to have a m_controlType of xtpControlComboBox.
I'm not very familiar with this application's code base since I didn't develop it, but I'm suspecting there is some mismanagement of the XTP derived control objects going on.
Can somebody tell me how to go about figuring out what's happening?
Thanks in advance for the assistance.
|
|
|
Regards,
Jeff |
|
![]() |
|
jhuckins
Newbie
Joined: 17 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Posted: 17 September 2007 at 5:33pm |
|
OK...pretty silly when I'm up here as the only one replying to my own posts, huh?
Well, this is what I discovered: The control that was causing me the problems was a (one and only) CXTPControlComboBox that was being statically instantiated as a member of a CXTPFrameWnd derived class object. So when it went out of scope with it's owner, it's destructor was being called.
Is it correct that XTP controls should ONLY be dynamically instantiated with "new" and NOT deleted because the CXTPControls object takes care of all of the garbage collecting? That doesn't seem like a good model if an application constantly instantiates new controls and doesn't have to clean up after themselves. If that ISN'T the way the model is supposed to work, then something is broken because when the combo box was being statically instantiated at startup, I did confirm that the destructor was only being called once, yet it was invalid at the time that th CXTPControls object performed a RefreshIndexes().
Bottom line is that now that I'm "new"ing the combo box and not deleting it, I don't get a crash and no complaints from CXTPControls that the reference count for one of the controls was not decremented properly.
I'm confused...
|
|
|
Regards,
Jeff |
|
![]() |
|
jhuckins
Newbie
Joined: 17 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Posted: 17 September 2007 at 8:14pm |
|
One more bit of info: Obviously NOT deleting the CXTPControlComboBox object is not what is supposed to be done because when I don't delete the control, the call to RtlValidateHeap() returns an error when the application shuts down.
J
|
|
|
Regards,
Jeff |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 18 September 2007 at 1:29am |
|
Hello, You just answered your question.
don't instantiate it as stratic member.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
jhuckins
Newbie
Joined: 17 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Posted: 18 September 2007 at 9:39am |
|
Well, it wasn't a static member. It was just a member that was instantiated with the window automatically as a member without having to instantiate after the window is instantiated.
It appears that I still have to delete it when the window goes away because when I don't, an exception gets thrown during shutdown of the application on a call to RtlVerifyHeap().
However, it is possible that the heap is corrupted by something else in the application.
So, my first question is: If I instantiate a CXTP control with new, does the CXTPControls object take care of the cleanup and delete it for me or am I supposed to call delete when the window goes away?
|
|
|
Regards,
Jeff |
|
![]() |
|
jhuckins
Newbie
Joined: 17 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Posted: 18 September 2007 at 1:22pm |
|
OK, we're cool. I just love taking over other people's code...
So, just a bit of background:
I'm porting a VC++ 6.0 application to VS 2005 and SDK for Vista/.NET 3.0, so along with the safe string changes, I'm dealing with Microsoft's move to adherence to the STL spec, so STL container operations that were OK in VC++ 6.0 are now broken.
Anyway, so what I found is that the heap was getting corrupted as a result of deleting an element in a std::list<> container after it had already been deleted by a call to std::list<>.erase(). So the heap issue was not related to not deleting the CXTPControlComboBox object. So all is well regarding XTP in the application now.
|
|
|
Regards,
Jeff |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 18 September 2007 at 1:26pm |
|
Hi,
You have create all controls using "new". CXTPControls will automatically delete them.
if you need member of CMainFrame add pointer and create it in constructor:
CXTPControlComboBox* m_pCombo
...
m_pCombo = new CXTPControlComboBox();
...
pToolBar->GetControls()->Add(m_pCombo);
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
jhuckins
Newbie
Joined: 17 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Posted: 20 September 2007 at 2:35pm |
|
Oleg,
You have been VERY helpful and I really appreciate all of your help.
The CXTPControlComboBox object is not created in the main window with the command bar, so there is no way to hand it to CXTPControls, however it appears that the cleanup is occuring anyway.
Does the "dynamically create with 'new' ALWAYS" rule apply to ALL CXT and CXTP controls. Even CXTPListCtrl objects and CXTPStatusBar objects?
The reason I ask is that an exception is thrown during shutdown of our app when the XTP DLL is terminating. There are a few things still being instantiated automatically as members of window classes.
Thanks!
|
|
|
Regards,
Jeff |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 21 September 2007 at 12:59am |
|
Hello,
Windows you can create as you need.
Only controls in CommandBars, Items in PropertyGrid, Items in TaskPanel have to be created dynamically.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |