From Jason Beverage, "I posted a question on osg users about resources not being properly released when using osgTerrain databases and multiple viewers are used a few weeks ago and I've found that at least part of the problem comes down to the fact that the nodes that are traversed by the GeometryTechnique are never actually added to the scene graph, and thus don't have releaseGLObjects called on them. I'm submitting a few changes that takes care of this by allowing the TerrainTechnique to provide a releaseGLObjects implementation. I've applied these changes in osgEarth and this example program no longer crashes on the second run, although I get corrupt geometry (see attached shot) which could be down to a driver issue. If I increment the context ID for the second viewer, I no longer get the corrupt geometry.

The attached changes are against OpenSceneGraph 2.8.2.

//Sample program.  Run against an osgEarth or VPB database based on osgTerrain.
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

int main(int argc, char** argv)
{
   osg::ArgumentParser arguments(&argc,argv);

   osgViewer::Viewer* viewer = new osgViewer::Viewer();
   viewer->setUpViewInWindow(100,
100,500,500);
   osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
   viewer->setSceneData( loadedModel.get() );
   viewer->run();
   delete viewer;

   viewer = new osgViewer::Viewer();
   viewer->setUpViewInWindow(100,100,500,500);
   loadedModel = osgDB::readNodeFiles(arguments);
   viewer->setSceneData( loadedModel.get() );
   viewer->run();
   delete viewer;
}"
This commit is contained in:
Robert Osfield 2009-11-20 11:08:40 +00:00
parent 833e79a79a
commit 5cd4faf05b
5 changed files with 33 additions and 0 deletions

View File

@ -76,6 +76,11 @@ class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique
void setFilterMatrixAs(FilterType filterType);
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
private:

View File

@ -51,6 +51,11 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object
/** Traverse the terrain subgraph.*/
virtual void traverse(osg::NodeVisitor& nv);
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const {}
protected:
void setDirty(bool dirty);

View File

@ -175,6 +175,12 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
static void setTileLoadedCallback(TileLoadedCallback* lc);
static osg::ref_ptr<TileLoadedCallback>& getTileLoadedCallback();
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~TerrainTile();

View File

@ -898,3 +898,9 @@ void GeometryTechnique::cleanSceneGraph()
{
}
void GeometryTechnique::releaseGLObjects(osg::State* state) const
{
if (_bufferData[0]._transform.valid()) _bufferData[0]._transform->releaseGLObjects(state);
if (_bufferData[1]._transform.valid()) _bufferData[1]._transform->releaseGLObjects(state);
}

View File

@ -463,3 +463,14 @@ void WhiteListTileLoadedCallback::loaded(osgTerrain::TerrainTile* tile, const os
}
}
void TerrainTile::releaseGLObjects(osg::State* state) const
{
Group::releaseGLObjects(state);
if (_terrainTechnique.valid())
{
_terrainTechnique->releaseGLObjects( state );
}
}