Fixed crash on intialization of static applications by moving the static mutexes inside singleton methods.
This commit is contained in:
@@ -17,8 +17,18 @@
|
||||
using namespace osgViewer;
|
||||
|
||||
typedef std::vector< osg::observer_ptr<Scene> > SceneCache;
|
||||
static OpenThreads::Mutex s_sceneCacheMutex;
|
||||
static SceneCache s_sceneCache;
|
||||
|
||||
static SceneCache& getSceneCache()
|
||||
{
|
||||
static SceneCache s_sceneCache;
|
||||
return s_sceneCache;
|
||||
}
|
||||
|
||||
static OpenThreads::Mutex& getSceneCacheMutex()
|
||||
{
|
||||
static OpenThreads::Mutex s_sceneCacheMutex;
|
||||
return s_sceneCacheMutex;
|
||||
}
|
||||
|
||||
Scene::Scene():
|
||||
osg::Referenced(true)
|
||||
@@ -26,21 +36,21 @@ Scene::Scene():
|
||||
setDatabasePager(osgDB::DatabasePager::create());
|
||||
setImagePager(new osgDB::ImagePager);
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_sceneCacheMutex);
|
||||
s_sceneCache.push_back(this);
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getSceneCacheMutex());
|
||||
getSceneCache().push_back(this);
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_sceneCacheMutex);
|
||||
for(SceneCache::iterator itr = s_sceneCache.begin();
|
||||
itr != s_sceneCache.end();
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getSceneCacheMutex());
|
||||
for(SceneCache::iterator itr = getSceneCache().begin();
|
||||
itr != getSceneCache().end();
|
||||
++itr)
|
||||
{
|
||||
Scene* scene = itr->get();
|
||||
if (scene==this)
|
||||
{
|
||||
s_sceneCache.erase(itr);
|
||||
getSceneCache().erase(itr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -97,9 +107,9 @@ void Scene::updateSceneGraph(osg::NodeVisitor& updateVisitor)
|
||||
|
||||
Scene* Scene::getScene(osg::Node* node)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_sceneCacheMutex);
|
||||
for(SceneCache::iterator itr = s_sceneCache.begin();
|
||||
itr != s_sceneCache.end();
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getSceneCacheMutex());
|
||||
for(SceneCache::iterator itr = getSceneCache().begin();
|
||||
itr != getSceneCache().end();
|
||||
++itr)
|
||||
{
|
||||
Scene* scene = itr->get();
|
||||
|
||||
Reference in New Issue
Block a user