Remove Camera's children before removing the Camera

Should work around OSG race condition ( http://forum.openscenegraph.org/viewtopic.php?t=16077 )
coverity_scan^2
scrawl 8 years ago
parent a44ba0e461
commit 641005b317

@ -147,6 +147,7 @@ namespace MWRender
CharacterPreview::~CharacterPreview () CharacterPreview::~CharacterPreview ()
{ {
mCamera->removeChildren(0, mCamera->getNumChildren());
mViewer->getSceneData()->asGroup()->removeChild(mCamera); mViewer->getSceneData()->asGroup()->removeChild(mCamera);
} }

@ -107,6 +107,10 @@ namespace MWRender
GlobalMap::~GlobalMap() GlobalMap::~GlobalMap()
{ {
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
removeCamera(*it);
for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it)
removeCamera(*it);
} }
void GlobalMap::render (Loading::Listener* loadingListener) void GlobalMap::render (Loading::Listener* loadingListener)
@ -507,7 +511,8 @@ namespace MWRender
void GlobalMap::cleanupCameras() void GlobalMap::cleanupCameras()
{ {
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it) for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
mRoot->removeChild(*it); removeCamera(*it);
mCamerasPendingRemoval.clear(); mCamerasPendingRemoval.clear();
for (ImageDestVector::iterator it = mPendingImageDest.begin(); it != mPendingImageDest.end();) for (ImageDestVector::iterator it = mPendingImageDest.begin(); it != mPendingImageDest.end();)
@ -524,4 +529,10 @@ namespace MWRender
it = mPendingImageDest.erase(it); it = mPendingImageDest.erase(it);
} }
} }
void GlobalMap::removeCamera(osg::Camera *cam)
{
cam->removeChildren(0, cam->getNumChildren());
mRoot->removeChild(cam);
}
} }

@ -56,6 +56,8 @@ namespace MWRender
*/ */
void cleanupCameras(); void cleanupCameras();
void removeCamera(osg::Camera* cam);
/** /**
* Mark a camera for cleanup in the next update. For internal use only. * Mark a camera for cleanup in the next update. For internal use only.
*/ */

@ -88,9 +88,9 @@ LocalMap::LocalMap(osgViewer::Viewer* viewer)
LocalMap::~LocalMap() LocalMap::~LocalMap()
{ {
for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it) for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it)
mRoot->removeChild(*it); removeCamera(*it);
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it) for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
mRoot->removeChild(*it); removeCamera(*it);
} }
const osg::Vec2f LocalMap::rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle) const osg::Vec2f LocalMap::rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle)
@ -275,6 +275,12 @@ osg::ref_ptr<osg::Texture2D> LocalMap::getFogOfWarTexture(int x, int y)
return found->second.mFogOfWarTexture; return found->second.mFogOfWarTexture;
} }
void LocalMap::removeCamera(osg::Camera *cam)
{
cam->removeChildren(0, cam->getNumChildren());
mRoot->removeChild(cam);
}
void LocalMap::markForRemoval(osg::Camera *cam) void LocalMap::markForRemoval(osg::Camera *cam)
{ {
CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), cam); CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), cam);
@ -293,11 +299,7 @@ void LocalMap::cleanupCameras()
return; return;
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it) for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
{ removeCamera(*it);
(*it)->removeChildren(0, (*it)->getNumChildren());
(*it)->setGraphicsContext(NULL);
mRoot->removeChild(*it);
}
mCamerasPendingRemoval.clear(); mCamerasPendingRemoval.clear();
} }

@ -63,6 +63,8 @@ namespace MWRender
osg::ref_ptr<osg::Texture2D> getFogOfWarTexture (int x, int y); osg::ref_ptr<osg::Texture2D> getFogOfWarTexture (int x, int y);
void removeCamera(osg::Camera* cam);
/** /**
* Indicates a camera has been queued for rendering and can be cleaned up in the next frame. For internal use only. * Indicates a camera has been queued for rendering and can be cleaned up in the next frame. For internal use only.
*/ */

@ -443,11 +443,13 @@ void Water::updateWaterMaterial()
{ {
if (mReflection) if (mReflection)
{ {
mReflection->removeChildren(0, mReflection->getNumChildren());
mParent->removeChild(mReflection); mParent->removeChild(mReflection);
mReflection = NULL; mReflection = NULL;
} }
if (mRefraction) if (mRefraction)
{ {
mRefraction->removeChildren(0, mRefraction->getNumChildren());
mParent->removeChild(mRefraction); mParent->removeChild(mRefraction);
mRefraction = NULL; mRefraction = NULL;
} }
@ -572,11 +574,13 @@ Water::~Water()
if (mReflection) if (mReflection)
{ {
mReflection->removeChildren(0, mReflection->getNumChildren());
mParent->removeChild(mReflection); mParent->removeChild(mReflection);
mReflection = NULL; mReflection = NULL;
} }
if (mRefraction) if (mRefraction)
{ {
mRefraction->removeChildren(0, mRefraction->getNumChildren());
mParent->removeChild(mRefraction); mParent->removeChild(mRefraction);
mRefraction = NULL; mRefraction = NULL;
} }

@ -412,6 +412,8 @@ void RenderManager::initialise()
void RenderManager::shutdown() void RenderManager::shutdown()
{ {
mGuiRoot->removeChildren(0, mGuiRoot->getNumChildren());
mSceneRoot->removeChild(mGuiRoot);
} }
MyGUI::IVertexBuffer* RenderManager::createVertexBuffer() MyGUI::IVertexBuffer* RenderManager::createVertexBuffer()

Loading…
Cancel
Save