[vtkusers] Access Violations in wxVTKRenderWindow Example

Charl P. Botha c.p.botha at its.tudelft.nl
Sun Jan 19 13:51:51 EST 2003


Prabhu (and list),

On Sun, Jan 19, 2003 at 06:30:20PM +0100, Charl P. Botha wrote:
> I have another interesting problem that I'm busy tracking down.  If you have
> a wxVTKRWI (RWI == RenderWindowInteractor) embedded in a wxFrame somewhere,
> there is no clean way to destroy that wxFrame.
> 
> If you call Destroy() on it (the recommended wx way), the vtkRenderWindow
> will cause an assert error (BadWindow) and terminate your application when
> it finally destructs, due to  the fact that the various vtkRenderWindow
> destructors assume that the window pointed to by the WindowId still exists,
> although it was destroyed during the Destroy() call.  Remember that from
> Python, there's no clean way to force immediate destruction of e.g. a
> wrapped vtkRenderWindow...

The solution is something like this when you Destroy() a frame containing a
wxVTKRenderWindowInteractor:

        # hide it so long
        self._view_frame.Show(0)
        # this event handler will finally Destroy the containing frame
        # when the vtkRenderWindow dies, NOT before
        vf = self._view_frame
        def rwDestroyEventHandler(o, e):
            vf.Destroy()
        # set it to be called on destruction
        self._rwi.GetRenderWindow().AddObserver('DeleteEvent',
                                                rwDestroyEventHandler)
        # kill our binding
        del self._rwi
        # now destroy all the containing frame's children
        self._view_frame.DestroyChildren()
        # unbind the _view_frame binding
        del self._view_frame

The self._rwi is a wxVTKRenderWindowInteractor and the self._view_frame is a
containing frame.  If you _don't_ do it this way and Destroy() the
containing frame, your application will crash with a BadWindow error (or
similar) as the RenderWindow destructor assumes that the window it's
rendering to still exists.

I don't know whether one should modify all the RenderWindows to be a bit
more intelligent about this.  Your thoughts?

Thanks,
Charl

-- 
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/



More information about the vtkusers mailing list