[vtkusers] wxPython & VTK: How to Destroy wxVTKRenderWindow without errors?

Kenneth Evans, Jr. evans at aps.anl.gov
Sun May 11 00:01:12 EDT 2008


Charl,

Thanks very much for the detailed instructions.  They seem to have worked.

Actually, just the lines dealing with the vtkRenderer (i.e. ren) were
sufficient.  

I am confused about the other lines.  First, I am mostly just using a
wxVTKRenderWindow, not a wxVTKRenderWindowInteractor.  (I haven't, in fact,
figured out how to make the cone6.py tutorial, which uses both, work in WX,
but I haven't tried very hard, yet.)  Note that neither wxVTKRenderWindow
nor wxVTKRenderWindowInteractor has a SetRenderWindow() method.  (At least
in the CVS versions I am using.)  I had in fact already tried doing that.
Also renWin.getRenderWindow() probably returns the same object as ren.
GetRenderWindow() and it has already been finalized.  It doesn't complain,
though.

This is what I am doing now, but it should probably be fixed up:

  def shutDownVTK(self):
    """ What has to be done to shut down VTK """
    # vtkRenderer
    if(self.ren != None):
      # Remove all actors from the renderer
      self.ren.RemoveAllViewProps()
      # Get the renderwindow to release all system resources (including
      # opengl context)
      self.ren.GetRenderWindow().Finalize()
      # Remove the reference
      del self.ren
    
#    # wxVTKRenderWindow
    if(self.renWin != None):
      self.renWin.GetRenderWindow().Finalize()
      # break link between RWI and RW
#      self.renWinI.SetRenderWindow(None) # No such method
    # Remove the reference
      del self.renWin

#    # wxVTKRenderWindowInteractor
    if(self.renWinI != None):
      self.renWinI.GetRenderWindow().Finalize()
      # break link between RWI and RW
#      self.renWinI.SetRenderWindow(None) ) # No such method
    # Remove the reference
      del self.renWinI

As I said, only implementing the first block was enough for my case.  That
apparently does shut down OpenGL.

Thanks again,

        -Ken

-----Original Message-----
From: cpbotha at medvis.org [mailto:cpbotha at medvis.org] On Behalf Of Charl
Botha
Sent: Friday, May 09, 2008 3:26 PM
To: Kenneth Evans
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] wxPython & VTK: How to Destroy wxVTKRenderWindow
without errors?

On Fri, May 9, 2008 at 7:18 PM, Kenneth Evans <evans at aps.anl.gov> wrote:
>  So, the question is how do you remove and replace a wxVTKRenderWindow
>  properly.

The problem is that VTK reference counts everything and WX doesn't.
So you have to be careful to disconnect all VTK and WX elements and
then also make sure that all VTK bindings (refs in C++) disappear.
Importantly, get the renderwindow to release its graphics resources.

This all comes down to the following SuperSafe(tm) approach:

# remove all actors from the renderer
ren.RemoveAllViewProps()
# get rid of your binding
del ren
# get the renderwindow to release all system resources (including
opengl context)
wxRWI.GetRenderWindow().Finalize()
# break link between RWI and RW
wxRWI.SetRenderWindow(None)
# get rid of our binding
del wxRWI
# now you can destroy the containing wx Window
wxWin.Destroy()

Good luck,
Charl

-- 
http://visualisation.tudelft.nl/CharlBotha




More information about the vtkusers mailing list