From 06cb8c030f13848de8e3fc663abbffeec38e3cfd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 28 Nov 2005 20:08:36 +0000 Subject: [PATCH] Added temporary ref_ptr to prevent the _image going out of scope due to another thread complete the texture::apply() while the present texture::apply() is still running. --- src/osg/Texture2D.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index 60e075c14..ec91da823 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -163,11 +163,14 @@ void Texture2D::apply(State& state) const else if (_image.valid() && _image->data()) { + // keep the image around at least till we go out of scope. + osg::ref_ptr image = _image; + // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); // compute the dimensions of the texture. - computeRequiredTextureDimensions(state,*_image,_textureWidth, _textureHeight, _numMipmapLevels); + computeRequiredTextureDimensions(state,*image,_textureWidth, _textureHeight, _numMipmapLevels); _textureObjectBuffer[contextID] = textureObject = generateTextureObject( @@ -180,13 +183,13 @@ void Texture2D::apply(State& state) const if (textureObject->isAllocated()) { //std::cout<<"Reusing texture object"<setAllocated(true); @@ -194,10 +197,10 @@ void Texture2D::apply(State& state) const // update the modified tag to show that it is upto date. - getModifiedCount(contextID) = _image->getModifiedCount(); + getModifiedCount(contextID) = image->getModifiedCount(); - if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC) + if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && image->getDataVariance()==STATIC) { Texture2D* non_const_this = const_cast(this); non_const_this->_image = 0;