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

Kenneth Evans evans at aps.anl.gov
Fri May 9 13:18:57 EDT 2008


Hi,

I have an application that continually makes new VTK plots.  The problem is
that when I destroy the previous wx.Panel that has the wxVTKRenderWindow and
the vtkRenderer with something like:

    self.plotPanel.Destroy()

then I get errors like:

ERROR: In ..\..\Rendering\vtkWin32OpenGLRenderWindow.cxx, line 233
vtkWin32OpenGLRenderWindow (01025F30): wglMakeCurrent failed in
MakeCurrent(), error: The handle is invalid.

ERROR: In ..\..\Rendering\vtkWin32OpenGLRenderWindow.cxx, line 233
vtkWin32OpenGLRenderWindow (01025F30): wglMakeCurrent failed in
MakeCurrent(), error: The handle is invalid.

ERROR: In ..\..\Rendering\vtkWin32OpenGLRenderWindow.cxx, line 124
vtkWin32OpenGLRenderWindow (01025F30): wglMakeCurrent failed in Clean(),
error: 6

If I don't call Destroy(), then I get all these errors at the end (and
presumably also have leaked memory).  I have tried a number of things, all
without successfully avoiding these errors, which appear in a
vtkOutputWindow.
 
So, the question is how do you remove and replace a wxVTKRenderWindow
properly.

Thanks,

        -Ken

More info:

I am using Python 2.5 and VTK 5.0.4 with wxVTKRenderWindow and
wxVTKRenderWindowInteractor replaced with the current versions in CVS
(because the distributed ones don't work).  This is on Windows XP.

The code for the wx.Panel is:

class PlotPanel(wx.Panel):
  """ Generic plot panel """
  def __init__(self, parent, id = wx.ID_ANY, color = None, dpi = None,
               **kwargs):
    wx.Panel.__init__(self, parent, id = id, **kwargs)

    self.renWin = wxVTKRenderWindow(self, -1)
    self.ren = vtk.vtkRenderer()
    self.renWin.GetRenderWindow().AddRenderer(self.ren)

    self.createPlot()

    self.sizer = wx.BoxSizer(wx.VERTICAL)
    self.sizer.Add(self.renWin, 1, wx.LEFT | wx.TOP | wx.GROW)
    self.SetSizerAndFit(self.sizer)

  def OnPaint(self, event):
    self.canvas.draw()
        
  def createPlot(self):
    """ Needs to be overridden in a subclass """
    pass

And a simple plot could be made by subclassing and overriding createPlot:

class DemoPanel(PlotPanel):
  """ Basic Cone Demo """
  def createPlot(self):
    """ Override createPlot from the base class """
    cone = vtk.vtkConeSource()
    cone.SetResolution(8)
    
    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInput(cone.GetOutput())
    
    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    self.ren.AddActor(coneActor)
    
    self.ren.ResetCamera()





More information about the vtkusers mailing list