Hi Sam,

You can't remove an object from it's a parent in a apply() method as
this would invalidate the iterators of the calling code (the
traverse() method that calls the node->accept() which in turn calls
the apply()).

It's safe to remove the children of a node you are passed in a the
apply method, but not removing that node from it's parent.  Another
approach is to collect the list of nodes you want to remove in list
during the traversal using the node visitor than have a method you
call after traversal that does all the operations on the nodes, this
way you can avoid invalidating iterators.

The second half of your post I couldn't make any sense of so can't
comment on this.

Robert.


On Tue, Jan 25, 2011 at 7:26 AM, Sam Warns <the_vincu...@hotmail.com> wrote:
> Hi,
>
> I was writing a Visitor that performed an extraction of certain elements from 
> a scenegraph. My first try was to remove the nodes in question from their 
> parents directly in the apply method which lead to some exceptions.
> So what am I doing wrong? I mean I would except some finalize method which is 
> called when the visitor is finished.
> Currently the only remaining function is the getter function for the nodes, 
> that should be extracted. So in apply I have stored references to the object 
> which I can only extract when using the getter so that the removal logic can 
> be executed.
> This works so far but if I do not call the getter no extraction code is 
> executed and nothing really happened.
>
> What am I doing wrong?
>
>
> Thank you,
> Sam
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=35941#35941
>
>
>
>
>
> _______________________________________________
> 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