Fixed crash on osgconv --compressed cow.osg cow.ive

This commit is contained in:
Robert Osfield 2006-06-26 15:18:14 +00:00
parent a39516c297
commit fdd5831b83

View File

@ -103,16 +103,23 @@ public:
osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(texture); osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(texture);
osg::Texture3D* texture3D = dynamic_cast<osg::Texture3D*>(texture); osg::Texture3D* texture3D = dynamic_cast<osg::Texture3D*>(texture);
osg::Image* image = texture2D ? texture2D->getImage() : texture3D ? texture3D->getImage() : 0; osg::ref_ptr<osg::Image> image = texture2D ? texture2D->getImage() : (texture3D ? texture3D->getImage() : 0);
if (image && if (image.valid() &&
(image->getPixelFormat()==GL_RGB || image->getPixelFormat()==GL_RGBA) && (image->getPixelFormat()==GL_RGB || image->getPixelFormat()==GL_RGBA) &&
(image->s()>=32 && image->t()>=32)) (image->s()>=32 && image->t()>=32))
{ {
texture->setInternalFormatMode(_internalFormatMode); texture->setInternalFormatMode(_internalFormatMode);
// need to disable the unref after apply, other the image could go out of scope.
bool unrefImageDataAfterApply = texture->getUnRefImageDataAfterApply();
texture->setUnRefImageDataAfterApply(false);
// get OpenGL driver to create texture from image. // get OpenGL driver to create texture from image.
texture->apply(*state); texture->apply(*state);
// restore the original setting
texture->setUnRefImageDataAfterApply(unrefImageDataAfterApply);
image->readImageFromCurrentTexture(0,true); image->readImageFromCurrentTexture(0,true);
texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT); texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);