Hello Ulrich.

My main_child ref pointer is just a backup of the last group added for easy
access. I never do something like addChild( main_child.get() ) out of this
scope.

I understand and will apply the programming practices you've suggested me to
do inside the update.

Do the UpdateCallback can pass a value not equal to the class that have been
attached to it ?

I thought it strange because i've made a similar updateCallback to another
class that blinks a component on screen each 1 second and i haven't done
more than a simple casting ( no dynamic_castings ) for the class and tested
a timer check the blink state for the case. Well, for this one i had no
segmentation faults.

I thought that the problem could be that osg does not allow addition of new
components during traversal for a question of integrity data check.

I'll be doing some tests here to report the results.

Thanks
Andre

2010/6/25 Ulrich Hertlein <u.hertl...@sandbox.de>

> 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
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to