[wxVTK] wxAuiNotebook with wxVTK
Brought to you by:
malat
From: KR L. <lo...@gm...> - 2008-04-07 20:56:25
|
Hello, I am using a wxAuiNotebook which has a page that is a wxVTKRenderWindowInteractor. Everything works fine until I either close the page or exit the application, at which time the application will crash or I get an error in the VTK debug window about trying to delete an object with a non-zero reference count, depending on how I handle deleting the wxVTKRenderWindowInteractor (wxVTK from here on). For simplicity, I'll focus on just the case of closing the application. If in the main frame's destructor, I do nothing to remove the wxVTK object, I get the error about deleting an object with a non-zero ref. count (makes sense). I added the wxVTKObject->Delete(), which does reduce the reference count to zero, but this causes a crash in wxObject (this is called from wxAuiNotebook::DeletePage()): bool wxObject::IsKindOf(wxClassInfo *info) const { wxClassInfo *thisInfo = GetClassInfo();// Crashes on this line return (thisInfo) ? thisInfo->IsKindOf(info) : false ; } I think I am successfully deleting the wxVTK object with the ->Delete() function, and then the notebook is trying to access it again in it's destructor. Is this something anyone has experienced before? Has anyone found a solution? I came up with a method that compiles and runs just fine, but I have doubts about whether or not this is a good (safe?) approach. I have not tested for memory leaks, but I suspect that if this method doesn't work, that will be why. Below is the code for my main frame's destructor: MainFrame::~MainFrame() { m_mgr.UnInit(); if (wxVTKObject) { wxVTKObject->Delete();// Delete the wxVTKRenderWindowInteractor the proper way wxWindow *Dummy = new wxWindow();// Create a dummy wxWindow // Assign the pointer for the wxVTKRenderWindowInteractor to point to a wxWindow // object instead. Now when the wxAuiNotebook is deleted, this will point to // something than can be deleted? wxVTKObject = (wxVTKRenderWindowInteractor*)Dummy; } } Is this OK? Is there a better way? I'm using wxWidgets 2.8.7 and VTK 5.0 in MSW. Thank you for your help, Kerry |