[osg-users] Problems shutting down Composite Viewer/View/Custom drawables

Cole, Charles E. (LARC-B702)[RAYTHEON TECHNICAL SERVICES COMPANY] charles.e.cole at nasa.gov
Fri Mar 27 09:51:13 PDT 2009

Hi all,

I've been chasing an error in my code for many, many days that I'm hoping that someone can help me track down.  I'll try to explain my application as best I can.

I'm using a composite viewer to load multiple views.  In each view, I'm loading a database scene (generally a TXP database) and overlaying OpenGL nodes that I load dynamically and add as drawables to the scenegraph.  I've created classes to encapsulate the composite viewer, view, and scene nodes.  For instance, I have a class that contains a composite viewer member variable; this class then creates multiple "View" classes that each contain an osgViewer::View member variable.  Each view then loads scene nodes as specified in a configuration file.  These nodes are contained in separate libraries and are loaded as drawables (I've created a class derived from osg::Drawable and overwrite the drawImplementation method for custom drawing).  Everything works great when creating the viewer, view, nodes, and even executing.  The problem comes when I try to destroy/close the window.

My attempted process to close is that I (1) set a flag on a render thread to stop calling viewer->frame (very similar to setDone(true)); (2) destroy the loaded drawables and free their associated libraries; (3) destroy the view, and thus it's associated camera and graphics context; and (4) destroy the composite viewer.  I use reference pointers in every case except for the composite viewer (although I've tried a reference pointer for it as well, but still get the same result).

When trying to follow the above process, the application crashes in the Node::releaseGLObjects method at line 523, if (_updateCallback.valid()) _updateCallback.releaseGLObjects(state).  

I also noticed during a debug walkthrough that the drawables drawImplementation method (and thus the custom drawable's own custom drawing methods) are still being called after the render thread has been stopped and destroyed.

So, some of my many questions are:

(1) Is there a preferred/required means or order for shutting down a composite viewer (and it's child nodes)?

(2) Separately, but possibly related ... I create a camera callback function to update the camera position per shared memory variables.  I'd like to destroy that callback function appropriately.  But, in doing so, how do I reset the camera's callback function such that it's not called once the custom callback function is destroyed?

(3) What's the appropriate means of stopping the rendering?  I thought that if viewer->frame() wasn't getting called, the drawImplementation method of the drawables would no longer be called, so I could then free those libraries.  But, unfortunately, they're still being called even though frame() is no longer called.  And thus, the libraries are trying to be freed when the viewer is still trying to draw them.

I am running multithreaded.  I'm using VS 2008 SP1 on Windows XP and Vista.

If anyone has any tips, pointers, something to point me in the right direction before I end up throwing the computer through the window, I'd greatly appreciate it.  I hope I've provided enough information.

Thanks so much in advance.


More information about the osg-users mailing list