Hi Zach,

On 2/4/07, Zach Deedler <[EMAIL PROTECTED]> wrote:
I'm trying to create a remove DOFTransform visitor.  I tried this:
void RemoveDofVisitor::apply(osg::Transform& node)
{
   if(dynamic_cast<const osgSim::DOFTransform*>(&node)){
      osgSim::DOFTransform* pDofNode =
dynamic_cast<osgSim::DOFTransform*>(&node);
      if ( pDofNode->getNumParents() > 0 ){
         osg::Group* parent = pDofNode->getParent(0);
         for( unsigned int i=0; i<pDofNode->getNumChildren(); i++ ){
            //TODO make this work for multiple parents.
            //Set grandparent of dofs children its parents.
            parent->addChild(pDofNode->getChild(i));
         }
         //Remove children from DOF
         pDofNode->removeChild(0, pDofNode->getNumChildren());
         //Remove dof from tree
         parent->removeChild(pDofNode);
         apply((osg::Node&)*parent);
      }
   }else{
      apply((osg::Node&)node);
   }
}

But, it crashes.  Should this first be done by collecting DOFs with a
visitor, and then removing them from the scene graph?  Or would it be safer
to replace the DOFTransform with an osg::Group?

Removing nodes during a NodeVisitor traversal will invalidate
iterators held on the stack (from the parents traversal of its
children).

The way to tackle this type of deletion to traversal the scene
accumulating all the nodes you want to delete into a list, then
traverse this list removing the nodes from their parents and a post
proces.

Robert
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to