[osg-users] Question on Node memory management.

eheft at dnaco.net eheft at dnaco.net
Tue Sep 25 15:55:36 PDT 2007


I am working on converting a project from SGI Performer in C
to OSG, so I am familiar with constructing a scene graph. 

For this project I load all the models I plan to use into a
data structure, at a later point in time based on the user
responses I swap out the sub-graphs that I wish displayed.
The problem is the memory manager ends up freeing my nodes.
I know the OSG answer will be to add a switch node as the
parent of each of the sub graphs then toggle those on and

Is there a way to tell OSG that I will let it know when I'm
done with a node? 

What should happen in this example snippet is loading two
models which are get swapped in/out by the user pressing "1"
or "2". 

What ends up happening is the program crashes the 2nd time I
tried to load either model. 

Setup in pseudo code based on the Glut example code is
something like ... 

osg::ref_ptr<osg::Node> pNode1;
osg::ref_ptr<osg::Node> pNode2;

void keyboard( unsigned char key, int /*x*/, int /*y*/ )
    switch( key )
        case '1':
           viewer->setSceneData( pNode1 );
        case '2':
           viewer->setSceneData( pNode2 );
        // other cases 

    // some initilization ...
    pNode1 = osgDB::readNodeFiles(File1);
    pNode2 = osgDB::readNodeFiles(File2);

    // more initilization
    viewer->setSceneData( pNode1 );


More information about the osg-users mailing list