[osg-users] What is the correct method for removing updatecallbacks?

beelzebob999-osg at yahoo.com beelzebob999-osg at yahoo.com
Fri Sep 28 07:26:19 PDT 2007


Yeah, I considered that, but had the same queasiness
about it you do.  I have decided to maintain a global
static list of callbacks, and just run through that
list once per frame, checking for those that are
"done" and clearing them out.  This won't be done
during the update traversal, but it will be done
outside of the "frame" call, so hopefully that won't
cause any threading issues.

--- "Thrall, Bryan" <bryan.thrall at flightsafety.com>
wrote:

> beelzebob999-osg at yahoo.com wrote on Friday,
> September 28, 2007 8:08 AM:
> > So, how do you get rid of update callbacks that
> are no
> > longer needed?  Do you have to do a separate
> traversal
> > just to check for update callbacks that are
> "done"?
> 
> At the risk of giving advice you shouldn't follow,
> I've had some luck
> with creating an osg::ref_ptr<> to the callback in
> its operator()
> function. Then it isn't deleted until the callback
> returns, at which
> point it's probably safe to delete. However, this is
> fragile, since it
> relies on the update visitor not doing anything with
> the callback other
> than calling its operator() function (see
>
osgUtil::UpdateVisitor::handle_callbacks_and_traverse()).
> 
> For example:
> 
> virtual void operator() (osg::Node* node,
> osg::NodeVisitor* nv)
>     {
>         // ... do stuff? ...
> 
>         traverse(node,nv);
> 
>         // ... do more stuff? ...
> 
>         osg::ref_ptr<osg::NodeCallback> thiscb =
> this; // don't delete
> until exit from this function
>        
> node->setUpdateCallback(this->getNestedCallback());
> // removes
> this callback in favor of nested callbacks (if any)
>     }
> 
> Probably a safer thing to do would be to implement
> your own update
> visitor, which would be less fragile and you could
> avoid the iterator
> problem Robert mentioned by being careful in your
> implementation.
> 
> > --- Robert Osfield <robert.osfield at gmail.com>
> wrote:
> > 
> >> Hi beelzebob666
> >> 
> >> You cannot modify the scene graph during
> >> renderingTraversals(), but
> >> can modify it in other phases of the scene graph
> >> operations.
> >> Modifying elements on the scene graph that affect
> >> traversal during
> >> traversal is a further restriction, simply
> because
> >> doing so
> >> invalidates iterators of the calling methods.
> >> 
> >> Robert.
> >> 
> >> On 9/28/07, beelzebob999-osg at yahoo.com
> >> <beelzebob999-osg at yahoo.com> wrote:
> >>> 
> >>> We ran into an interesting crash, caused by the
> fact
> >>> that an update callback would set the update
> callback
> >>> pointer of its node to NULL (causing it to be
> freed),
> >>> before calling traverse on the node.  It seems
> to me
> >>> it should be possible to do a pre-order delete
> >>> traversal, but this causes a crash.
> >>> 
> >>> This raises kind of an interesting question...
> how do
> >>> you go about removing update callbacks from the
> scene?
> >>>  Since you can only modify a scene during the
> update
> >>> traversal, it seems like you are forced into
> having
> >>> update callbacks remove themselves, which leads
> to an
> >>> unpleasant case of a "this" pointer deleting
> itself.
> -- 
> Bryan Thrall
> FlightSafety International
> Bryan.Thrall at flightsafety.com
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 




More information about the osg-users mailing list