From d22208f70181b78db016a64b57a48f37b1f4c65f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 21 May 2007 18:46:57 +0000 Subject: [PATCH] Added extra checks to make sure that graphics operations arn't done on no longer valid graphics contexts --- include/osgViewer/Viewer | 6 +++--- src/osgViewer/CompositeViewer.cpp | 29 ++++++++++++++++++----------- src/osgViewer/Viewer.cpp | 26 ++++++++++++-------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index 8a8da7695..04454f065 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -176,16 +176,16 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View releaseContext(); - if (gc && gc->makeCurrent()) _currentContext = gc; + if (gc && gc->valid() && gc->makeCurrent()) _currentContext = gc; } inline void releaseContext() { - if (_currentContext.valid()) + if (_currentContext.valid() && _currentContext->valid()) { _currentContext->releaseContext(); - _currentContext = 0; } + _currentContext = 0; } diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index 31d754763..b767ea1da 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -429,15 +429,16 @@ void CompositeViewer::startThreading() void CompositeViewer::checkWindowStatus() { - unsigned int numThreadsIncludingMainThread = computeNumberOfThreadsIncludingMainRequired(); - if (numThreadsIncludingMainThread != _numThreadsOnBarrier) - { - stopThreading(); - - if (numThreadsIncludingMainThread > 1) startThreading(); - } + Contexts contexts; + getContexts(contexts); - if (numThreadsIncludingMainThread==0) _done = true; + // osg::notify(osg::INFO)<<"Viewer::checkWindowStatus() - "<realize(); - if (_realizeOperation.valid()) + if (_realizeOperation.valid() && gc->valid()) { gc->makeCurrent(); @@ -1007,7 +1008,13 @@ void CompositeViewer::eventTraversal() { case(osgGA::GUIEventAdapter::CLOSE_WINDOW): { + bool wasThreading = areThreadsRunning(); + if (wasThreading) stopThreading(); + gw->close(); + + if (wasThreading) startThreading(); + break; } default: @@ -1201,7 +1208,7 @@ void CompositeViewer::renderingTraversals() ++itr) { if (_done) return; - if (!((*itr)->getGraphicsThread())) + if (!((*itr)->getGraphicsThread()) && (*itr)->valid()) { (*itr)->makeCurrent(); (*itr)->runOperations(); @@ -1220,7 +1227,7 @@ void CompositeViewer::renderingTraversals() { if (_done) return; - if (!((*itr)->getGraphicsThread())) + if (!((*itr)->getGraphicsThread()) && (*itr)->valid()) { (*itr)->makeCurrent(); (*itr)->swapBuffers(); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index d70b53e3f..148ebc879 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -1041,7 +1041,7 @@ void Viewer::startThreading() { if (_threadsRunning) return; - osg::notify(osg::INFO)<<"Viewer::startThreading() - starting threading"<getGraphicsContext()) cameras.push_back(_camera.get()); + if (!onlyActive || (_camera->getGraphicsContext() && _camera->getGraphicsContext()->valid()) ) cameras.push_back(_camera.get()); for(Slaves::iterator itr = _slaves.begin(); itr != _slaves.end(); ++itr) { - if (!onlyActive || itr->_camera->getGraphicsContext()) cameras.push_back(itr->_camera.get()); + if (!onlyActive || (itr->_camera->getGraphicsContext() && itr->_camera->getGraphicsContext()->valid()) ) cameras.push_back(itr->_camera.get()); } } @@ -1646,7 +1643,7 @@ void Viewer::realize() osg::GraphicsContext* gc = *citr; gc->realize(); - if (_realizeOperation.valid()) + if (_realizeOperation.valid() && gc->valid()) { gc->makeCurrent(); @@ -1901,11 +1898,12 @@ void Viewer::eventTraversal() { case(osgGA::GUIEventAdapter::CLOSE_WINDOW): { - // stopThreading(); + bool wasThreading = areThreadsRunning(); + if (wasThreading) stopThreading(); gw->close(); - // startThreading(); + if (wasThreading) startThreading(); break; } @@ -2141,7 +2139,7 @@ void Viewer::renderingTraversals() ++itr) { if (_done) return; - if (!((*itr)->getGraphicsThread())) + if (!((*itr)->getGraphicsThread()) && (*itr)->valid()) { makeCurrent(*itr); (*itr)->runOperations(); @@ -2159,7 +2157,7 @@ void Viewer::renderingTraversals() { if (_done) return; - if (!((*itr)->getGraphicsThread())) + if (!((*itr)->getGraphicsThread()) && (*itr)->valid()) { makeCurrent(*itr); (*itr)->swapBuffers();