Hi Andre,

On 25/06/10 1:06 , Andre Simoes wrote:
> I've made a main osg::Group with an osg::NodeCallback attached to call
> some stuff each update.
> 
> inside my osg::NodeCallback i have:
> 
> void
> MyCallback::
> operator()( osg::Node* node, osg::NodeVisitor* nv)
> {
>       Frame *frame = (Frame*)node;
>       if( ! frame->main_child )
>       {
>             frame->main_child = new osg::Group;
>             frame->addChild( main_child.get() );
>       }
> }
> 
> The problem is that when it calls  frame->addChild( main_child.get() );
> the program badly ends.

There might be two problems with the above code:
a) the 'node' might not be of the proper type in which case frame->main_child
   could return all kinds of garbage; it's safer to use
   Frame* frame = dynamic_cast<Frame>(node);
   if (frame && !frame->main_child)
   ...
b) you might have a circular dependency, if main_child is a ref_ptr that is 
owned by Frame
and also added as a child

Cheers,
/ulrich
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to