diff --git a/src/osgDB/InputStream.cpp b/src/osgDB/InputStream.cpp index 3d4a77a06..cbce77c23 100644 --- a/src/osgDB/InputStream.cpp +++ b/src/osgDB/InputStream.cpp @@ -684,7 +684,7 @@ osg::Image* InputStream::readImage(bool readFromExternal) image = new osg::Image; image->setOrigin( (osg::Image::Origin)origin ); image->setImage( s, t, r, internalFormat, pixelFormat, dataType, - (unsigned char*)data, (osg::Image::AllocationMode)mode, packing ); + (unsigned char*)data, osg::Image::USE_NEW_DELETE, packing ); } // _mipmapData diff --git a/src/osgPlugins/ive/Image.cpp b/src/osgPlugins/ive/Image.cpp index d9b1a4580..e0358e8c4 100644 --- a/src/osgPlugins/ive/Image.cpp +++ b/src/osgPlugins/ive/Image.cpp @@ -133,9 +133,10 @@ void Image::read(DataInputStream* in) // Read image data if any + unsigned int dataSize = 0; if(in->readBool()) { - unsigned int dataSize = (unsigned int)in->readInt(); + dataSize = (unsigned int)in->readInt(); //static int totalSize = 0; @@ -154,6 +155,12 @@ void Image::read(DataInputStream* in) } _mipmapData.swap(mipmapData); + + // If data size does not match computed image size, then clear mipmaps since we probably have invalid offsets + if (dataSize > 0 && dataSize != getTotalSizeInBytesIncludingMipmaps()) + { + _mipmapData.clear(); + } } else{ in_THROW_EXCEPTION("Image::read(): Expected Image identification.");