From Pjotr Svetachov, "when you restart threading

with startThreading/stopThreading the _drawQueue and _availableQueue
are not reset properly. This can lead to a deadlock when threading is
started again. So before threading is started again the queues must be
reset. This deadlock is also reported earlier by someone else in here:
http://forum.openscenegraph.org/viewtopic.php?p=43415#43415"
This commit is contained in:
Robert Osfield
2013-01-23 17:38:28 +00:00
parent d3e9b61f2b
commit bada884342
3 changed files with 20 additions and 0 deletions

View File

@@ -69,6 +69,8 @@ class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation
virtual void release();
virtual void reset();
/** Force update of state associated with cameras. */
void setCameraRequiresSetUp(bool flag);
bool getCameraRequiresSetUp() const;
@@ -101,6 +103,9 @@ class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation
/** Release any thread waiting on the queue, even if the queue is empty. */
void release();
/** Reset to fefault state (_isReleased = false)*/
void reset();
/** Take a SceneView from the queue. Can return 0 if release() is called when the queue is empty. */
osgUtil::SceneView* takeFront();

View File

@@ -304,6 +304,13 @@ void Renderer::ThreadSafeQueue::release()
_cond.broadcast();
}
void Renderer::ThreadSafeQueue::reset()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
_queue.clear();
_isReleased = false;
}
osgUtil::SceneView* Renderer::ThreadSafeQueue::takeFront()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
@@ -902,6 +909,13 @@ void Renderer::release()
_drawQueue.release();
}
void Renderer::reset(){
_availableQueue.reset();
_availableQueue.add(_sceneView[0].get());
_availableQueue.add(_sceneView[1].get());
_drawQueue.reset();
}
void Renderer::setCameraRequiresSetUp(bool flag)
{
for (int i = 0; i < 2; ++i)

View File

@@ -336,6 +336,7 @@ void ViewerBase::startThreading()
{
renderer->setGraphicsThreadDoesCull(graphicsThreadsDoesCull);
renderer->setDone(false);
renderer->reset();
++numViewerDoubleBufferedRenderingOperation;
}
}