From 44c125a8013e3e53019471307872793199b2e309 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 26 Jun 2008 16:45:50 +0000 Subject: [PATCH] Changed the removeCamera() method so that it now actively calls releaseGLObjects() on all children of a camera that aren't shared with other cameras on that context. This change fixes problems with allocating and deleting views. --- src/osg/GraphicsContext.cpp | 67 ++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index 86ad0e8b8..94dbe7fb1 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -213,24 +213,11 @@ unsigned int GraphicsContext::createNewContextID() s_contextIDMap[contextID]._numContexts = 1; osg::notify(osg::INFO)<<"GraphicsContext::createNewContextID() creating contextID="< osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(); -#endif + osg::notify(osg::INFO)<<"Updating the MaxNumberOfGraphicsContexts to "<setMaxNumberOfGraphicsContexts( contextID + 1 ); - } - + // update the the maximum number of graphics contexts, + // to ensure that texture objects and display buffers are configured to the correct size. + osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts( contextID + 1 ); return contextID; } @@ -746,15 +733,49 @@ void GraphicsContext::addCamera(osg::Camera* camera) void GraphicsContext::removeCamera(osg::Camera* camera) { - for(Cameras::iterator itr = _cameras.begin(); - itr != _cameras.end(); - ++itr) + Cameras::iterator itr = std::find(_cameras.begin(), _cameras.end(), camera); + if (itr != _cameras.end()) { - if (*itr == camera) + // find a set of nodes attached the camera that we are removing that isn't + // shared by any other cameras on this GraphicsContext + typedef std::set NodeSet; + NodeSet nodes; + for(unsigned int i=0; igetNumChildren(); ++i) { - _cameras.erase(itr); - return; + nodes.insert(camera->getChild(i)); } + + for(Cameras::iterator citr = _cameras.begin(); + citr != _cameras.end(); + ++citr) + { + if (citr != itr) + { + osg::Camera* otherCamera = *citr; + for(unsigned int i=0; igetNumChildren(); ++i) + { + NodeSet::iterator nitr = nodes.find(otherCamera->getChild(i)); + if (nitr != nodes.end()) nodes.erase(nitr); + } + } + } + + // now release the GLobjects associated with these non shared nodes + for(NodeSet::iterator nitr = nodes.begin(); + nitr != nodes.end(); + ++nitr) + { + const_cast(*nitr)->releaseGLObjects(_state.get()); + } + + // release the context of the any RenderingCache that the Camera has. + if (camera->getRenderingCache()) + { + camera->getRenderingCache()->releaseGLObjects(_state.get()); + } + + _cameras.erase(itr); + } }