Hi Jeff,

The most likely cause of the problem is that the object is probably
being deleted which you remove it from the scene graph, if you are
just using C pointers at the top level to keep a handle to object then
this is certainly the problem.  The solution is very simple, just use
ref_ptr<> to keep a proper reference to the object and you'll have no
problems with memeory managenent.   Read Don's article about ref_ptr<>
on the Documentation/KnowledgeBase section of the website.

Robert.

On 6/9/06, Jeff Hanes <[EMAIL PROTECTED]> wrote:
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/

Reply via email to