Added collateReferencesToDependentCameras() and clearReferencesToDependentCameras() methods into RenderStage and SceneView, and use
of these methods in src/osgViewer/Renderer.cpp to make sure that the draw thread keeps references to all in scene graph Cameras that are being used by the drawing threads, to keep the Camera's alive even when the main thread removes these Cameras from the scene graph.
This commit is contained in:
@@ -200,11 +200,11 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
|
||||
}
|
||||
}
|
||||
|
||||
// search for a drawable in the RenderLead list equal to the attached the one attached to StateGraph user data
|
||||
// search for a drawable in the RenderLeaf list equal to the attached the one attached to StateGraph user data
|
||||
// as this will be our special light point drawable.
|
||||
osgUtil::StateGraph::LeafList::iterator litr;
|
||||
for(litr = rg->_leaves.begin();
|
||||
litr != rg->_leaves.end() && (*litr)->_drawable.get()!=drawable;
|
||||
litr != rg->_leaves.end() && (*litr)->_drawable!=drawable;
|
||||
++litr)
|
||||
{}
|
||||
|
||||
|
||||
@@ -1350,7 +1350,7 @@ unsigned int RenderStage::computeNumberOfDynamicRenderLeaves() const
|
||||
}
|
||||
|
||||
|
||||
void osgUtil::RenderStage::setMultisampleResolveFramebufferObject(osg::FrameBufferObject* fbo)
|
||||
void RenderStage::setMultisampleResolveFramebufferObject(osg::FrameBufferObject* fbo)
|
||||
{
|
||||
if (fbo && fbo->isMultisample())
|
||||
{
|
||||
@@ -1359,3 +1359,45 @@ void osgUtil::RenderStage::setMultisampleResolveFramebufferObject(osg::FrameBuff
|
||||
}
|
||||
_resolveFbo = fbo;
|
||||
}
|
||||
|
||||
void RenderStage::collateReferencesToDependentCameras()
|
||||
{
|
||||
_dependentCameras.clear();
|
||||
|
||||
for(RenderStageList::iterator itr = _preRenderList.begin();
|
||||
itr != _preRenderList.end();
|
||||
++itr)
|
||||
{
|
||||
itr->second->collateReferencesToDependentCameras();
|
||||
osg::Camera* camera = itr->second->getCamera();
|
||||
if (camera) _dependentCameras.push_back(camera);
|
||||
}
|
||||
|
||||
for(RenderStageList::iterator itr = _postRenderList.begin();
|
||||
itr != _postRenderList.end();
|
||||
++itr)
|
||||
{
|
||||
itr->second->collateReferencesToDependentCameras();
|
||||
osg::Camera* camera = itr->second->getCamera();
|
||||
if (camera) _dependentCameras.push_back(camera);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderStage::clearReferencesToDependentCameras()
|
||||
{
|
||||
for(RenderStageList::iterator itr = _preRenderList.begin();
|
||||
itr != _preRenderList.end();
|
||||
++itr)
|
||||
{
|
||||
itr->second->collateReferencesToDependentCameras();
|
||||
}
|
||||
|
||||
for(RenderStageList::iterator itr = _postRenderList.begin();
|
||||
itr != _postRenderList.end();
|
||||
++itr)
|
||||
{
|
||||
itr->second->collateReferencesToDependentCameras();
|
||||
}
|
||||
|
||||
_dependentCameras.clear();
|
||||
}
|
||||
|
||||
@@ -1728,3 +1728,17 @@ bool SceneView::getStats(Statistics& stats)
|
||||
return _renderStage->getStats(stats);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneView::collateReferencesToDependentCameras()
|
||||
{
|
||||
if (_renderStage.valid()) _renderStage->collateReferencesToDependentCameras();
|
||||
if (_renderStageLeft.valid()) _renderStageLeft->collateReferencesToDependentCameras();
|
||||
if (_renderStageRight.valid()) _renderStageRight->collateReferencesToDependentCameras();
|
||||
}
|
||||
|
||||
void SceneView::clearReferencesToDependentCameras()
|
||||
{
|
||||
if (_renderStage.valid()) _renderStage->clearReferencesToDependentCameras();
|
||||
if (_renderStageLeft.valid()) _renderStageLeft->clearReferencesToDependentCameras();
|
||||
if (_renderStageRight.valid()) _renderStageRight->clearReferencesToDependentCameras();
|
||||
}
|
||||
|
||||
@@ -384,6 +384,11 @@ void Renderer::draw()
|
||||
|
||||
if (sceneView && !_done)
|
||||
{
|
||||
// since we are running the draw thread in parallel with the main thread it's possible to unreference Camera's
|
||||
// that are still being used by this rendering thread, so to prevent this we'll take references to all these
|
||||
// Camera's and the clear these references once we've completed the whole draw dispatch.
|
||||
sceneView->collateReferencesToDependentCameras();
|
||||
|
||||
if (_compileOnNextDraw)
|
||||
{
|
||||
compile();
|
||||
@@ -485,6 +490,7 @@ void Renderer::draw()
|
||||
stats->setAttribute(frameNumber, "Draw traversal time taken", osg::Timer::instance()->delta_s(beforeDrawTick, afterDrawTick));
|
||||
}
|
||||
|
||||
sceneView->clearReferencesToDependentCameras();
|
||||
}
|
||||
|
||||
DEBUG_MESSAGE<<"end draw() "<<this<<std::endl;
|
||||
|
||||
Reference in New Issue
Block a user