Page 1 of 1

Destroy for wxDialog based window

Posted: Sun Feb 08, 2009 4:57 pm
by spectrum
Hi all,

i am trying to destroy a wxDialog based object using "Destroy" inside OnCancel.

My first question is, is it necessary ? I can't find a clear answer in the documentation, but i want be sure the memory allocated from the dialog object is released, and don't seems that clicking on the [X] destroy/free the object.

Anyway, using "Destroy" inside OnCancel, the program crash, this is the call stack:

Code: Select all

#0 64ED3C93	wxListBase::DeleteObject() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#1 6F699B9E	wxDataViewCtrl::~wxDataViewCtrl() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_adv_gcc_custom.dll:??)
#2 00453E99	~ListViewDevSelect(this=0x14aabb0) (D:/archivio/sviluppo2/angelx/projects/wxLi/include//views.hh:200)
#3 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#4 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#5 62B11944	wxPanel::~wxPanel() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#6 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#7 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#8 62B11944	wxPanel::~wxPanel() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#9 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#10 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#11 62A6EF01	wxControlBase::~wxControlBase() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#12 62A388C0	wxNotebook::~wxNotebook() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#13 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#14 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#15 62B11944	wxPanel::~wxPanel() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#16 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#17 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#18 00457FC9	~DlgSwConf(this=0x143df20) (D:/archivio/sviluppo2/angelx/projects/test/include//dlgswconf.hh:28)
#19 62A5C308	wxAppBase::DeletePendingObjects() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#20 62A5C3B3	wxAppBase::ProcessIdle() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#21 64EA05AE	wxEventLoopManual::Run() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#22 64E815B5	wxAppConsoleBase::MainLoop() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#23 64EC750E	wxEntryReal() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#24 629C7841	wxEntry() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#25 0042A8C8	[email protected](hInstance=0x400000, hPrevInstance=0x0, nCmdShow=10) (D:\archivio\sviluppo2\angelx\projects\test\src\main.cc:53)
#26 00446B54	main() (??:??)

any help is really appreciated,
many thanks

Posted: Sun Feb 08, 2009 9:22 pm
by Disch
Is this a modal dialog? If it is, you must close it with EndModal() and not Destroy(). Otherwise for modeless dialogs the way I usually do it is to just call Close(), but Destroy() should also work.

Posted: Sun Feb 08, 2009 10:43 pm
by JimFairway
Hi,

Based on the call stack, I would say the issue lies with however you're calling your wxDataViewCtrl::AssociateModel.
Did you call DecRef() more than once?

Jim

Posted: Mon Feb 09, 2009 9:16 am
by spectrum
thanks all,

Jim,
i was not decreasing the reference count, and this was a first good reason for the crash.
Note that wxDataViewModel is reference counted, derives from wxObjectRefData and cannot be deleted directly as it can be shared by several wxDataViewCtrls. This implies that you need to decrease the reference count after associating the model with a control ..
Now i have seen the sample code in the documentation, and "DecRef" once just after the association.

Anyway, now i still have a crash deleting the columns that are added to the model after the association:

Code: Select all

#0 6F684E2F	wxDataViewColumnBase::~wxDataViewColumnBase() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_adv_gcc_custom.dll:??)
#1 6F69EA63	wxDataViewColumn::~wxDataViewColumn() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_adv_gcc_custom.dll:??)
#2 64ED3B6D	wxListBase::DoDeleteNode() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#3 64ED3BA1	wxListBase::Clear() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#4 6F699BB1	wxDataViewCtrl::~wxDataViewCtrl() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_adv_gcc_custom.dll:??)
#5 0045466E	~ListViewDevSelect(this=0x14aa6d0) (D:/archivio/sviluppo2/angelx/projects/test/include//views.hh:202)
#6 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#7 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#8 62B11944	wxPanel::~wxPanel() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#9 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#10 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#11 62B11944	wxPanel::~wxPanel() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#12 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#13 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#14 62A6EF01	wxControlBase::~wxControlBase() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#15 62A388C0	wxNotebook::~wxNotebook() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#16 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#17 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#18 62B11944	wxPanel::~wxPanel() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#19 62AE8045	wxWindowBase::DestroyChildren() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#20 62A024A5	wxWindow::~wxWindow() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#21 00458719	~DlgSwConf(this=0x143d9f8) (D:/archivio/sviluppo2/angelx/projects/test/include//dlgswconf.hh:28)
#22 62A5C308	wxAppBase::DeletePendingObjects() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#23 62A5C3B3	wxAppBase::ProcessIdle() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#24 64EA05AE	wxEventLoopManual::Run() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#25 64E815B5	wxAppConsoleBase::MainLoop() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#26 64EC750E	wxEntryReal() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxbase290u_gcc_custom.dll:??)
#27 629C7841	wxEntry() (C:\wxWidgets-2.9.0\lib\gcc_dll\wxmsw290u_core_gcc_custom.dll:??)
#28 0042B08C	[email protected](hInstance=0x400000, hPrevInstance=0x0, nCmdShow=10) (D:\archivio\sviluppo2\angelx\projects\test\src\main.cc:53)
#29 00447388	main() (??:??)
many thanks

Posted: Mon Feb 09, 2009 12:41 pm
by spectrum
thanks all,

i solved finally.

I was using a custom render, created a single time but assigned to 2 columns. Now i create 2 render objects, 1 per column, and all works fine.

Many thanks

spec.