From 22e6f6038f764b88e1c2acb1c04dcc6749157aa4 Mon Sep 17 00:00:00 2001 From: gwaldron Date: Mon, 10 Sep 2018 08:00:41 -0400 Subject: [PATCH] osgText: fixed thread-safety issues in Glyph and Font --- include/osgText/Glyph | 2 ++ src/osgText/Font.cpp | 30 +++++++++++++++--------------- src/osgText/Glyph.cpp | 6 ++++++ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/osgText/Glyph b/include/osgText/Glyph index 2d1eafa05..c2fe58299 100644 --- a/include/osgText/Glyph +++ b/include/osgText/Glyph @@ -126,6 +126,8 @@ protected: typedef std::vector< osg::ref_ptr > TextureInfoList; TextureInfoList _textureInfoList; + + mutable OpenThreads::Mutex _textureInfoListMutex; }; class OSGTEXT_EXPORT GlyphGeometry : public osg::Referenced diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 599dd6f6e..10b9139b9 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -337,15 +337,16 @@ Glyph* Font::getGlyph(const FontResolution& fontRes, unsigned int charcode) GlyphMap::iterator gitr = glyphmap.find(charcode); if (gitr!=glyphmap.end()) return gitr->second.get(); } - } - Glyph* glyph = _implementation->getGlyph(fontResUsed, charcode); - if (glyph) - { - addGlyph(fontResUsed, charcode, glyph); - return glyph; + Glyph* glyph = _implementation->getGlyph(fontResUsed, charcode); + if (glyph) + { + //addGlyph(fontResUsed, charcode, glyph); + _sizeGlyphMap[fontResUsed][charcode] = glyph; + return glyph; + } + else return 0; } - else return 0; } Glyph3D* Font::getGlyph3D(const FontResolution &fontRes, unsigned int charcode) @@ -364,16 +365,15 @@ Glyph3D* Font::getGlyph3D(const FontResolution &fontRes, unsigned int charcode) Glyph3DMap::iterator gitr = glyphmap.find(charcode); if (gitr!=glyphmap.end()) return gitr->second.get(); } - } - Glyph3D* glyph = _implementation->getGlyph3D(fontResUsed, charcode); - if (glyph) - { - OpenThreads::ScopedLock lock(_glyphMapMutex); - _sizeGlyph3DMap[fontResUsed][charcode] = glyph; - return glyph; + Glyph3D* glyph = _implementation->getGlyph3D(fontResUsed, charcode); + if (glyph) + { + _sizeGlyph3DMap[fontResUsed][charcode] = glyph; + return glyph; + } + else return 0; } - else return 0; } void Font::setThreadSafeRefUnref(bool threadSafe) diff --git a/src/osgText/Glyph.cpp b/src/osgText/Glyph.cpp index 2654a7392..6971ecdd7 100644 --- a/src/osgText/Glyph.cpp +++ b/src/osgText/Glyph.cpp @@ -464,6 +464,8 @@ float Glyph::getVerticalAdvance() const { return _verticalAdvance; } void Glyph::setTextureInfo(ShaderTechnique technique, TextureInfo* info) { + OpenThreads::ScopedLock lock(_textureInfoListMutex); + if (technique>=_textureInfoList.size()) { _textureInfoList.resize(technique+1); @@ -473,11 +475,15 @@ void Glyph::setTextureInfo(ShaderTechnique technique, TextureInfo* info) const Glyph::TextureInfo* Glyph::getTextureInfo(ShaderTechnique technique) const { + OpenThreads::ScopedLock lock(_textureInfoListMutex); + return (technique<_textureInfoList.size()) ? _textureInfoList[technique].get() : 0; } Glyph::TextureInfo* Glyph::getOrCreateTextureInfo(ShaderTechnique technique) { + OpenThreads::ScopedLock lock(_textureInfoListMutex); + if (technique>=_textureInfoList.size()) { _textureInfoList.resize(technique+1);