From cb8daaaee14649b702d26e198396fdc85687837e Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 11 Jun 2016 00:25:09 +0200 Subject: [PATCH] Do not query the texture's image in osgMyGUI::OSGTexture Doing so could result in a race condition if the draw thread is about to delete the image (UnRefImageDataAfterApply enabled) --- components/myguiplatform/myguitexture.cpp | 24 ++++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/components/myguiplatform/myguitexture.cpp b/components/myguiplatform/myguitexture.cpp index 2ba78c26b..85ff3e3b5 100644 --- a/components/myguiplatform/myguitexture.cpp +++ b/components/myguiplatform/myguitexture.cpp @@ -86,9 +86,12 @@ namespace osgMyGUI if (!mImageManager) throw std::runtime_error("No imagemanager set"); - mTexture = new osg::Texture2D(mImageManager->getImage(fname)); + osg::ref_ptr image (mImageManager->getImage(fname)); + mTexture = new osg::Texture2D(image); mTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); mTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); + mTexture->setTextureWidth(image->s()); + mTexture->setTextureHeight(image->t()); // disable mip-maps mTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); @@ -107,8 +110,6 @@ namespace osgMyGUI { if(!mTexture.valid()) return 0; - osg::Image *image = mTexture->getImage(); - if(image) return image->s(); return mTexture->getTextureWidth(); } @@ -116,8 +117,6 @@ namespace osgMyGUI { if(!mTexture.valid()) return 0; - osg::Image *image = mTexture->getImage(); - if(image) return image->t(); return mTexture->getTextureHeight(); } @@ -128,15 +127,12 @@ namespace osgMyGUI if (mLockedImage.valid()) throw std::runtime_error("Texture already locked"); - mLockedImage = mTexture->getImage(); - if(!mLockedImage.valid()) - { - mLockedImage = new osg::Image(); - mLockedImage->allocateImage( - mTexture->getTextureWidth(), mTexture->getTextureHeight(), mTexture->getTextureDepth(), - mTexture->getSourceFormat(), mTexture->getSourceType() - ); - } + mLockedImage = new osg::Image(); + mLockedImage->allocateImage( + mTexture->getTextureWidth(), mTexture->getTextureHeight(), mTexture->getTextureDepth(), + mTexture->getSourceFormat(), mTexture->getSourceType() + ); + return mLockedImage->data(); }