From c9f6a3f7ca930fba754fbc2ac58a65d3e6923947 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 4 Sep 2007 12:32:47 +0000 Subject: [PATCH] Added mutex into osgText::Font::GlphTexture to marshel adding to and reading from glyph list --- include/osgText/Font | 7 +++++-- src/osgText/Font.cpp | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/osgText/Font b/include/osgText/Font index 03f20a6a8..ae3be1be7 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -270,6 +270,7 @@ public: virtual ~GlyphTexture(); + // parameter used to compute the size and position of empty space // in the texture which could accomodate new glyphs. int _margin; @@ -282,8 +283,10 @@ public: typedef std::vector< const Glyph* > GlyphPtrList; typedef osg::buffered_object< GlyphPtrList > GlyphBuffer; - GlyphRefList _glyphs; - mutable GlyphBuffer _glyphsToSubload; + GlyphRefList _glyphs; + mutable GlyphBuffer _glyphsToSubload; + + mutable OpenThreads::Mutex _mutex; }; diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 1fec08a98..0a9fbfc32 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -484,6 +484,7 @@ bool Font::GlyphTexture::getSpaceForGlyph(Glyph* glyph, int& posX, int& posY) void Font::GlyphTexture::addGlyph(Glyph* glyph, int posX, int posY) { + OpenThreads::ScopedLock lock(_mutex); _glyphs.push_back(glyph); for(unsigned int i=0;i<_glyphsToSubload.size();++i) @@ -507,6 +508,8 @@ void Font::GlyphTexture::apply(osg::State& state) const if (contextID>=_glyphsToSubload.size()) { + OpenThreads::ScopedLock lock(_mutex); + // graphics context is beyond the number of glyphsToSubloads, so // we must now copy the glyph list across, this is a potential // threading issue though is multiple applies are happening the @@ -612,6 +615,8 @@ void Font::GlyphTexture::apply(osg::State& state) const static bool s_subloadAllGlyphsTogether = false; if (!s_renderer) { + OpenThreads::ScopedLock lock(_mutex); + s_renderer = glGetString(GL_RENDERER); osg::notify(osg::INFO)<<"glGetString(GL_RENDERER)=="< lock(_mutex); + if (!s_subloadAllGlyphsTogether) { if (newTextureObject)