Hi,

As we've discussed, that only occasionally helps. In the boring single-viewer, 
single-view case, it works, but no one would notice there was a problem there 
anyway as nothing would actually render incorrectly.

My application just uses the camera created for it by OSG when an 
osgViewer::View is created, and I think it's reasonable to expect OSG to clear 
up things it's created itself. I'm under the impression that you do, too.

I've been having a poke around, and it seems to me that one possible option 
would be to call releaseGLObjects on a camera being removed from an 
osg::GraphicsContext when it's the only one attached. In such a situation, we 
already call it on the camera's non-shared child nodes (which is all of them) 
and its rendering cache, so this only adds the renderer and callbacks as extra 
things being released. It's my belief that this could only cause unwanted 
releasing in the case where all the cameras were removed from a context and 
then new ones were added. I think such a situation is probably unlikely (but 
you'd know better) and not much would be different to how things are now, as 
any attached nodes are already being released. There's also an added bonus that 
the function can return early as there'd be no need to work out which child 
nodes may or may not be shared.

The diff that fixes my use case is

Code:

diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp
index 1a35497d0..e6113eb9a 100644
--- a/src/osg/GraphicsContext.cpp
+++ b/src/osg/GraphicsContext.cpp
@@ -741,6 +741,12 @@ void GraphicsContext::addCamera(osg::Camera* camera)

 void GraphicsContext::removeCamera(osg::Camera* camera)
 {
+    if (_cameras.size() == 1 && camera == _cameras.front())
+    {
+        _cameras.clear();
+        camera->releaseGLObjects(_state.get());
+        return;
+    }
     Cameras::iterator itr = std::find(_cameras.begin(), _cameras.end(), 
camera);
     if (itr != _cameras.end())
     {




How does this look to you?

Cheers,
Chris

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=76605#76605





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

Reply via email to