Hi there,
i wrote a class inherit from NodeVistor to remove all the scribe node from the
scene. However, after the execution leave my apply function, the system
crashed. I think that's because i changed the structure of the scene since i
removed nodes from scene when visiting, and that may make some iterator
unusable.
so, is it available to change the structure of scene in a NodeVistor ? If yes,
is there anything to take care?
following are code episode:
1. constructor :
ClearSelectionNodeVisitor::ClearSelectionNodeVisitor(void)
:NodeVisitor(NodeVisitor::UPDATE_VISITOR,NodeVisitor::TRAVERSE_ALL_CHILDREN)
{}
2. apply function
void ClearSelectionNodeVisitor::apply(Node& node){
Node::ParentList parentList=node.getParents();
//iterate all the parent to find whether it has a Scribe as parent node.
for(Node::ParentList::iterator it=parentList.begin();
it!=parentList.end();++it){
Group* parent=*it;
Scribe* scribe=dynamic_cast<Scribe*>(parent);
if(parent&&scribe)
{
Node::ParentList ancestorList=parent->getParents();
//replace the scribe in its parent with the current node who is the
child of this scribe.
for(Node::ParentList::iterator ast=ancestorList.begin();
ast!=ancestorList.end();++ast){
(*ast)->replaceChild(scribe,&node);
}
// node has been moved, so the parentList maybe changed .
re-identify the begin.
it=parentList.begin ();
}
}
traverse(node);
}
any comment is appreciative.
Regards,
Abe. Zhu
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org