Fixed crash on intialization of static applications by moving the static mutexes inside singleton methods.
This commit is contained in:
@@ -44,7 +44,11 @@ osg::ref_ptr<Font>& Font::getDefaultFont()
|
||||
return s_defaultFont;
|
||||
}
|
||||
|
||||
static OpenThreads::ReentrantMutex s_FontFileMutex;
|
||||
static OpenThreads::ReentrantMutex& getFontFileMutex()
|
||||
{
|
||||
static OpenThreads::ReentrantMutex s_FontFileMutex;
|
||||
return s_FontFileMutex;
|
||||
}
|
||||
|
||||
std::string osgText::findFontFile(const std::string& str)
|
||||
{
|
||||
@@ -52,7 +56,7 @@ std::string osgText::findFontFile(const std::string& str)
|
||||
std::string filename = osgDB::findDataFile(str);
|
||||
if (!filename.empty()) return filename;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(s_FontFileMutex);
|
||||
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(getFontFileMutex());
|
||||
|
||||
static osgDB::FilePathList s_FontFilePath;
|
||||
static bool initialized = false;
|
||||
@@ -107,7 +111,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename, const osgDB::R
|
||||
if (foundFile.empty())
|
||||
foundFile = filename;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_FontFileMutex);
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getFontFileMutex());
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
@@ -129,7 +133,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename, const osgDB::R
|
||||
|
||||
osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_FontFileMutex);
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getFontFileMutex());
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
@@ -168,7 +172,7 @@ osg::ref_ptr<Font> osgText::readRefFontFile(const std::string& filename, const o
|
||||
if (foundFile.empty())
|
||||
foundFile = filename;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_FontFileMutex);
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getFontFileMutex());
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
@@ -188,7 +192,7 @@ osg::ref_ptr<Font> osgText::readRefFontFile(const std::string& filename, const o
|
||||
|
||||
osg::ref_ptr<Font> osgText::readRefFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_FontFileMutex);
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getFontFileMutex());
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
|
||||
@@ -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