Added temporary ref_ptr<osg::Image> to prevent the _image going out of scope

due to another thread complete the texture::apply() while the present texture::apply()
is still running.
This commit is contained in:
Robert Osfield
2005-11-28 20:08:36 +00:00
parent 0514427c0a
commit 06cb8c030f

View File

@@ -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<osg::Image> 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"<<std::endl;
applyTexImage2D_subload(state,GL_TEXTURE_2D,_image.get(),
applyTexImage2D_subload(state,GL_TEXTURE_2D,image.get(),
_textureWidth, _textureHeight, _internalFormat, _numMipmapLevels);
}
else
{
//std::cout<<"Creating new texture object"<<std::endl;
applyTexImage2D_load(state,GL_TEXTURE_2D,_image.get(),
applyTexImage2D_load(state,GL_TEXTURE_2D,image.get(),
_textureWidth, _textureHeight, _numMipmapLevels);
textureObject->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<Texture2D*>(this);
non_const_this->_image = 0;