[osg-users] bug - resources aren't properly deallocated when a viewer is destroyed

2008-11-21 Thread brettwiesner

Hi,

I have a simple example that shows that if you run a viewer, tear it 
down and run it again, textures are missing. (winXP, 2.6.0). It appears 
that resources such as Textures and DisplayLists are leaking and 
corrupting runs.


The attached example simply creates a viewer and loads the cow.osg file. 
Press esc to exit the viewer which removes the cow from the scene and 
tears the viewer down. Then another viewer is created and the cow is 
loaded again. This time, the cow has no textures.


What calls are necessary to properly deallocate resources when tearing 
down the viewer so that future viewers can be created and load the next 
resources?


Thanks,
Brett

#include osg/ref_ptr
#include osgDB/ReadFile
#include osgViewer/Viewer
#include osgGA/TrackballManipulator
#include osgDB/ReadFile
#include osgDB/WriteFile

void testViewerTeardown()
{
{
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer;
osg::ref_ptrosg::Group root = new osg::Group;
viewer-setUpViewOnSingleScreen(0);
viewer-setSceneData(root.get());
viewer-setCameraManipulator(new osgGA::TrackballManipulator());
viewer-realize();
{
std::string originalFile = Cow.osg;
osg::ref_ptrosgDB::ReaderWriter::Options options = 
osgDB::Registry::instance()-getOptions(); 
osg::ref_ptrosg::Node modelNode = 
osgDB::readNodeFile(originalFile, options.get()); 
root-addChild(modelNode.get());
viewer-run();  
root-removeChildren(0,root-getNumChildren());
}
}

{ 
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer;
osg::ref_ptrosg::Group root = new osg::Group;
viewer-setUpViewOnSingleScreen(0);
viewer-setSceneData(root.get());
viewer-setCameraManipulator(new osgGA::TrackballManipulator());
viewer-realize();
{
std::string originalFile = Cow.osg;
osg::ref_ptrosgDB::ReaderWriter::Options options = 
osgDB::Registry::instance()-getOptions(); 
osg::ref_ptrosg::Node modelNode = 
osgDB::readNodeFile(originalFile, options.get()); 
root-addChild(modelNode.get());
viewer-run();  
root-removeChildren(0,root-getNumChildren());
}
}
} ___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] bug - resources aren't properly deallocated when a viewer is destroyed

2008-11-21 Thread Robert Osfield
Hi Brett,

The Viewer does it best to deallocate and clean up all buffers on the
scene graphs that it knows about, but your code is hidding the scene
graph from it by removing them from the view's scene graph so these
removed elements do go throw the OpenGL clean up process.

If you really want to use the OSG in this kack handed way then call
releaseGLObjects() on the subgraph that you've detacthed.

You example code was pretty ropey - it's not an app in its own right
so one had covert it into a application, and then because of adding of
adding of the scene graph after realize and that no home was recent
the viewer's camera wasn't pointed at the scene graph, so one could
verify anything.  In future could you please provide example codes
that can be run as-as, and ones that you can actually see something.

Robert.

On Fri, Nov 21, 2008 at 4:49 PM, brettwiesner [EMAIL PROTECTED] wrote:
 Hi,

 I have a simple example that shows that if you run a viewer, tear it down
 and run it again, textures are missing. (winXP, 2.6.0). It appears that
 resources such as Textures and DisplayLists are leaking and corrupting runs.

 The attached example simply creates a viewer and loads the cow.osg file.
 Press esc to exit the viewer which removes the cow from the scene and
 tears the viewer down. Then another viewer is created and the cow is loaded
 again. This time, the cow has no textures.

 What calls are necessary to properly deallocate resources when tearing down
 the viewer so that future viewers can be created and load the next
 resources?

 Thanks,
 Brett


 #include osg/ref_ptr
 #include osgDB/ReadFile
 #include osgViewer/Viewer
 #include osgGA/TrackballManipulator
 #include osgDB/ReadFile
 #include osgDB/WriteFile

 void testViewerTeardown()
 {
{
osg::ref_ptrosgViewer::Viewer viewer = new
 osgViewer::Viewer;
osg::ref_ptrosg::Group root = new osg::Group;
viewer-setUpViewOnSingleScreen(0);
viewer-setSceneData(root.get());
viewer-setCameraManipulator(new
 osgGA::TrackballManipulator());
viewer-realize();
{
std::string originalFile = Cow.osg;
osg::ref_ptrosgDB::ReaderWriter::Options options =
 osgDB::Registry::instance()-getOptions();
osg::ref_ptrosg::Node modelNode =
 osgDB::readNodeFile(originalFile, options.get());
root-addChild(modelNode.get());
viewer-run();
root-removeChildren(0,root-getNumChildren());
}
}

{
osg::ref_ptrosgViewer::Viewer viewer = new
 osgViewer::Viewer;
osg::ref_ptrosg::Group root = new osg::Group;
viewer-setUpViewOnSingleScreen(0);
viewer-setSceneData(root.get());
viewer-setCameraManipulator(new
 osgGA::TrackballManipulator());
viewer-realize();
{
std::string originalFile = Cow.osg;
osg::ref_ptrosgDB::ReaderWriter::Options options =
 osgDB::Registry::instance()-getOptions();
osg::ref_ptrosg::Node modelNode =
 osgDB::readNodeFile(originalFile, options.get());
root-addChild(modelNode.get());
viewer-run();
root-removeChildren(0,root-getNumChildren());
}
}
 }
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org