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

Jean-Sébastien Guay jean-sebastien.guay at cm-labs.com
Fri Mar 27 11:35:40 PDT 2009

Hi Charles,

> When I referred to "destroy", what I'm doing is calling 'delete' on the classes that contain the ref_ptrs.  For instance, I call delete on my view class, and in the view class' destructor, I (eventually) call delete on the drawables. So I'm in effect doing what you're saying, with the exception of the class containing the composite viewer.  I'll change some code around to reflect that and see how it goes.

One thing you need to be careful of when deriving classes from OSG base 
classes which themselves derive from osg::Referenced ... In most cases, 
the destructors of those classes should be protected. Since they're 
normally protected already (as in osg::Object, osg::Drawable, etc) you 
shouldn't expose them in public scope in your derived class, which would 
allow them to be (erroneously) deleted at any time by the application 
instead of being deleted automatically when their ref count goes down to 0.

I've had a similar problem once, which was being caused by a 
double-delete. I was manually deleting a custom drawable or node (I 
can't remember) and then since it was still in the scene graph, it was 
being deleted when the viewer went out of scope too.

In general, trust ref_ptr to manage anything derived from osg::Referenced.

Hope this helps,

Jean-Sebastien Guay    jean-sebastien.guay at cm-labs.com

More information about the osg-users mailing list