Re: [wxVTK] wxAuiNotebook with wxVTK
Brought to you by:
malat
|
From: Kerry L. <lo...@gm...> - 2008-04-08 15:54:18
|
Hello Mathieu, I am new to wxWidgets and have never used any version other than 2.8.7, so I can't say how new wx->Destroy() is. I did try to set the pointer to my wxVTKObject to NULL, but the app still crashes on exit. I don't think the problem is that wxWidgets wants to delete a NULL pointer (that's supposed to be safe?), it's that when the wxAuiNotebook::DeletePage() function is called (this gets called when the app closes as well as when a page closes), it tries to call member functions of the wxWindow that is on the notebook page. Looking through the code I get very confused - in wxAuiNotebook::DeletePage(), it makes this assignment: wxWindow* wnd = m_tabs.GetWindowFromIdx(page_idx); I would have guessed that this pointer is supposed to point to the page containing the wxVTKObject (which is now NULL), but then it calls wnd->IsKindOf() a few lines later. The crash occurs inside of IsKindOf() (when it tries to call wxObject::GetClassInfo()), not at the call for IsKindOf(). I can't explain why this is... In any case, I still prefer Sander's solution because it works for closing the application as well as closing just that one notebook tab. If I were to call wxVTK->Delete() and set the pointer to NULL, I'd have to put code in wxVTK's parent's destructor and I'd also have to catch notebook page close events, check to see if that page was a wxVTKObject, then do the special handling. Thanks for the responses! -Kerry On Tue, Apr 8, 2008 at 11:07 AM, Mathieu Malaterre < mat...@gm...> wrote: > Hi Kerry, > > I never realized that wxWindows now has a ::Destroy, > > http://docs.wxwidgets.org/2.8.6/wx_wxwindow.html#wxwindow > > My guess is that VTK->Delete() & wxWidgets::Destroy() might now have > conflicting behavior. What I do not understand is that no one before > experienced the issue. Is this wx->Destroy() really that new ? > > The thing that I still do not understand is why don't you do something > like that: > > wxVTKObject->Delete(); > wxVTKObject = NULL; // tell wx not do manipulate this pointer anymore > > I have not looked at this wxAUI thingy... > > HTH > -Mathieu > > On Mon, Apr 7, 2008 at 10:56 PM, KR Loux <lo...@gm...> wrote: > > 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 > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > > Register now and save $200. Hurry, offer ends at 11:59 p.m., > > Monday, April 7! Use priority code J8TLD2. > > > > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > > _______________________________________________ > > Wxvtk-users mailing list > > Wxv...@li... > > https://lists.sourceforge.net/lists/listinfo/wxvtk-users > > > > > > > > -- > Mathieu > |