From a59e93a0df21a71b2d131a92d423dd137ffc6b3a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 23 Apr 2008 14:10:41 +0000 Subject: [PATCH] Added mutex to object creation to avoid a race condition when using threaded multiple graphics context --- src/osg/TextureRectangle.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 7a48af647..9170ea8f8 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -146,9 +146,13 @@ void TextureRectangle::apply(State& state) const // current OpenGL context. const unsigned int contextID = state.getContextID(); + + static OpenThreads::Mutex s_mutex; + // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); - + + if (textureObject != 0) { @@ -189,9 +193,12 @@ void TextureRectangle::apply(State& state) const } else if (_image.valid() && _image->data()) { + + OpenThreads::ScopedLock lock(s_mutex); + // we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object. _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_RECTANGLE); - + textureObject->bind(); applyTexParameters(GL_TEXTURE_RECTANGLE, state); @@ -205,6 +212,8 @@ void TextureRectangle::apply(State& state) const TextureRectangle* non_const_this = const_cast(this); non_const_this->_image = 0; } + + } else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) {