From 5ae1eb711aab1188466b6b9b5448babe3a4d86f0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 31 Aug 2007 20:16:02 +0000 Subject: [PATCH] To solve creations with multi-threaded creation of text, added mutex to Font, and use of this mutex in Text, and added mutex to the reading of fonts. --- include/osgText/Font | 8 ++++++++ src/osgText/Text.cpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/include/osgText/Font b/include/osgText/Font index c9a561b4d..4a038276c 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -26,6 +26,8 @@ #include #include +#include + namespace osgText { class Font; @@ -159,6 +161,11 @@ public: * for all graphics contexts. */ virtual void releaseGLObjects(osg::State* state=0) const; + typedef OpenThreads::Mutex FontMutex; + + /** Get the mutex that enables the serialization of calls to this font.*/ + FontMutex& getSerializeFontCallsMutex() const { return _serializeFontCallsMutex; } + protected: virtual ~Font(); @@ -172,6 +179,7 @@ protected: typedef std::pair< unsigned int, unsigned int > SizePair; typedef std::map< SizePair, GlyphMap > SizeGlyphMap; + mutable FontMutex _serializeFontCallsMutex; osg::ref_ptr _texenv; osg::ref_ptr _stateset; diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 3b30e9555..416e7d256 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -448,6 +448,7 @@ String::iterator Text::computeLastCharacterOnLine(osg::Vec2& cursor, String::ite return lastChar; } + void Text::computeGlyphRepresentation() { Font* activefont = getActiveFont(); @@ -462,6 +463,8 @@ void Text::computeGlyphRepresentation() computePositions(); //to reset the origin return; } + + OpenThreads::ScopedLock lock(activefont->getSerializeFontCallsMutex()); // initialize bounding box, it will be expanded during glyph position calculation _textBB.init();