Added extra checks to make sure that graphics operations arn't done on no longer valid graphics contexts

This commit is contained in:
Robert Osfield
2007-05-21 18:46:57 +00:00
parent d74d62ed0b
commit d22208f701
3 changed files with 33 additions and 28 deletions

View File

@@ -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;
}

View File

@@ -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() - "<<contexts.size()<<std::endl;
if (contexts.size()==0)
{
_done = true;
if (areThreadsRunning()) stopThreading();
}
}
@@ -738,7 +739,7 @@ void CompositeViewer::realize()
osg::GraphicsContext* gc = *citr;
gc->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();

View File

@@ -1041,7 +1041,7 @@ void Viewer::startThreading()
{
if (_threadsRunning) return;
osg::notify(osg::INFO)<<"Viewer::startThreading() - starting threading"<<std::endl;
// osg::notify(osg::NOTICE)<<"Viewer::startThreading() - starting threading"<<std::endl;
// release any context held by the main thread.
releaseContext();
@@ -1050,6 +1050,8 @@ void Viewer::startThreading()
Contexts contexts;
getContexts(contexts);
osg::notify(osg::INFO)<<"Viewer::startThreading() - contexts.size()="<<contexts.size()<<std::endl;
Cameras cameras;
getCameras(cameras);
@@ -1306,18 +1308,13 @@ void Viewer::checkWindowStatus()
Contexts contexts;
getContexts(contexts);
osg::notify(osg::NOTICE)<<"Viewer::checkWindowStatus() - "<<contexts.size()<<std::endl;
// osg::notify(osg::NOTICE)<<"Viewer::checkWindowStatus() - "<<contexts.size()<<std::endl;
if (contexts.size()==0)
{
_done = true;
if (areThreadsRunning()) stopThreading();
}
else if (_numWindowsOpenAtLastSetUpThreading != contexts.size() && _threadsRunning)
{
stopThreading();
startThreading();
}
}
@@ -1403,13 +1400,13 @@ void Viewer::getCameras(Cameras& cameras, bool onlyActive)
{
cameras.clear();
if (!onlyActive || _camera->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();