[osg-users] Question on Node memory management.

Robert Osfield robert.osfield at gmail.com
Wed Sep 26 01:05:27 PDT 2007


Hi,

Use of ref_ptr<> ensures safe memory management both within the scene
graph and outwith.  If you want to switch subgraphs on/off then use
either osg::Switch or a Node::setNodeMask(.).  You can manually add
elements/remove elements during the update phase, but in general its
better to just leave them in the scene graph and use Switch or
NodeMask.

As for GLUT, its not a good platform for serious graphics application
development, you are better off migrating to use osgViewer's native
windowing support, this will allow you to use multi-threaded and
multiple graphics contexts/graphics windows.

Robert.

On 9/25/07, eheft at dnaco.net <eheft at dnaco.net> wrote:
> Hello,
>
> 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
> off.
>
> 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 );
>            break;
>         case '2':
>            viewer->setSceneData( pNode2 );
>            break;
>         // other cases
>     }
> }
>
> main()
> {
>     // some initilization ...
>     pNode1 = osgDB::readNodeFiles(File1);
>     pNode2 = osgDB::readNodeFiles(File2);
>
>     // more initilization
>     viewer->setSceneData( pNode1 );
>     viewer->realize();
>
>     glutMainLoop();
> }
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list