When you remove() the tankTransorm, it is being automatically deleted because of OSG's use of ref_ptr's. To make this work, use osg::ref_ptr<osg::MatrixTransform> tankTransform = new ... Then keep the tankTransform stored somewhere. By doing this, you will always have a positive count on the tankTransform ref_ptr and the node (and it's children including callbacks) will not be deleted. Just a note, when using ref_ptr's in add/remove calls you need to "dereference" them: addChild(tankTransform.get()).
Take a look at the examples and you will see the use of ref_ptrs. Also, look on the wiki and read Don's article on ref_ptrs. Corbin -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Hanes Sent: Friday, June 09, 2006 8:26 AM To: [email protected] Subject: [osg-users] problem with removeChild() & addChild() i'm having a problem when I remove a node from the root node of a scene graph. specifically, it appears that the update callback is getting messed up. the reason this is important is that I want to hold the object out of sight for a while, then add it back to the scene graph and keep going ... my code looks something like this (based on Joseph Sullivan's excellent tutorials) osg::Node* tankNode = osgDB::readNodeFile("blah, blah, blah"); osg::MatrixTransform * tankTransform = new osg::MatrixTransform(); tankTransform->setUpdateCallback( new orbit() ); // drives in a circle tankTransform->addChild( tankNode ); scene_root->addChild( tankTransform ); then later, i do something like this: scene_root->removeChild( tankTransform ); and still later, i want to do this: scene_root->addChild( tankTransform ); but it causes some kind of error (which are hard to debug on a windows system since OSG and visual studio fight over the display). after tracking things down, i found that if i print the value of the callback (the pointer) before and after the remove cout << "hide_unit() callback = 0x" << tankTransform->getUpdateCallback() << endl; root->removeChild( tankTransform ); cout << "hide_unit() callback = 0x" << tankTransform->getUpdateCallback() << endl; i get the following ... hide_unit() callback = 0x0919C510 hide_unit() callback = 0xDDDDDDDD if i store the pointer and try to check inside the callback, it is also messed up internally. any ideas about what's causing this and what I can do to fix it? thanks, Jeff Hanes _______________________________________________ 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/
