[vtkusers] Bug in vtkWin32OpenGLRenderWindow when using own Interactor and windowhandle
Sander Niemeijer
niemeijer at science-and-technology.nl
Mon Feb 25 06:07:48 EST 2002
I was trying to get the wxVTKWindow by David Marshall and Brian Todd
class to work under Windows but encountered some illegal memory access
when destructing the wxVTKWindow. Something that didn't happen when
running on a unix system. After some digging I found the root cause of
this problem:
It seems that vtkWin32OpenGLRenderWindow in its destructor checks
whether it owns the windowhandle. If it does it will clean up nicely.
However with wxVTKWindow the windowhandle provided by wxWindows is used
and thus when vtkWin32OpenGLRenderWindow gets destructed the cleanup
part of the destructor is not called. This means that
vtkWin32OpenGLRenderWindow::Clean() will not be called and
ren->SetRenderWindow(NULL) will also not be called. This means that
after the destruction of the renderwindow the renderers (which haven't
reached their referencecount=0, because they are still referenced by an
InteractorStyle) have a reference to a non-existing renderwindow. In my
code this caused a problem when trying to destruct the
renderwindowinteractor, because at some point a
vtkOpenGLPolyDataMapper::ReleaseGraphicsResources(vtkWindow *win) was
called with this illegal windowreference and thus my program crashed at
win->MakeCurrent().
The problem does not appear on unix because vtkXOpenGLRenderWindow
doesn't check for ownership of the windowhandle.
I am not sure how to fix this bug properly, because I don't really know
why the check for ownership is done inside the
vtkWin32OpenGLRenderWindow destructor. My guess for the fix would be:
---
if (this->WindowId)
{
this->Clean();
if (this->OwnWindow)
{
ReleaseDC(this->WindowId, this->DeviceContext);
// can't set WindowId=NULL, needed for DestroyWindow
this->DeviceContext = NULL;
// clear the extra data before calling destroy
SetWindowLong(this->WindowId,4,(LONG)0);
DestroyWindow(this->WindowId);
}
}
---
but then again, I'm no windows programming expert, so I could be
completely wrong.
P.S. The current hack I use in my program to eliminate the illegal
memory access is to explicitly set the renderwindow of the render to
NULL just before I delete the renderwindow and renderwindowinteractor
(=wxVTKwindow).
Regards,
Sander Niemeijer
More information about the vtkusers
mailing list