Fixed crash on intialization of static applications by moving the static mutexes inside singleton methods.

This commit is contained in:
Robert Osfield
2010-11-12 09:48:21 +00:00
parent 6cc7e109d3
commit e1ee96b3f2
2 changed files with 31 additions and 17 deletions

View File

@@ -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)