Hi Pawan,

You need to use a ref_ptr<Node> instead of a raw C pointer to make
sure the ref counting in the scene graph doesn't delete the object
when you remove it from the scene graph.

See http://donburns.net/OSG/Articles/RefPointers/RefPointers.html

Robert.

On 2/16/07, Pawan Harish <[EMAIL PROTECTED]> wrote:
Hi,
    Thanks Robert, for the previous answer. I am facing trouble removing
and adding children using addChild() of osg::Group. Following is the code

main()
{
   osg::Group *rootnode = new osg::Group;
   osg::MatrixTransform *rotator = new osg::MatrixTransform;
   osg::Node *cessna = osgDB::readNodeFile("cessna.osg");
   osg::Node *glider = osgDB::readNodeFile("glider.osg");
   osg::Node *cow = osgDB::readNodeFile("cow.osg");

   rootnode->addChild(glider);
   rootnode->addChild(rotator);
   rotator->addChild(glider);
   rotator->addChild(cessna);
   rotator->addChild(cow);

   viewer.setSceneData(rootnode);
   MultiOut::instance()->SetRootNode(rootnode);
   viewer.realize();
   while( !viewer.done() )
     {
         viewer.sync();
         viewer.update();
         viewer.frame();
     }

   //Rotator has 3 children glider, cow, cessna
   for(int i=0;i<int(rotator->getNumChildren());i++)
     {
         osg::Node *node = rotator->getChild(i);
         rotator->removeChild(i);
         cout<<"Removed Child: "<<node->getName()<<endl;
         rotator->addChild(node);

        //When cow is removed and added again this gives seg fault
         cout<<"Re-Added Child: "<<node->getName()<<endl;
     }
}

When the child is a non-group it removes and adds it successfully but if
it is a group I get a segmentation fault.

Pawan Harish

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

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

Reply via email to