Introduced use of ref_ptr<> and private destructor to tighen up memory management and avoid users attempting to inappropriately delete TexCoordRange.

This commit is contained in:
Robert Osfield 2019-01-09 08:38:16 +00:00
parent 466bbc6740
commit 3da76932e6
2 changed files with 5 additions and 3 deletions

View File

@ -120,6 +120,8 @@ class OSGDB_EXPORT ImageOptions : public osgDB::Options
} }
double _x,_y,_w,_h; double _x,_y,_w,_h;
protected:
virtual ~TexCoordRange() {}
}; };

View File

@ -142,7 +142,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
// int destHeight = osg::minimum(dataHeight,4096); // int destHeight = osg::minimum(dataHeight,4096);
osgDB::ImageOptions::TexCoordRange* texCoordRange = 0; osg::ref_ptr<osgDB::ImageOptions::TexCoordRange> texCoordRange;
osgDB::ImageOptions* imageOptions = dynamic_cast<osgDB::ImageOptions*>(const_cast<osgDB::ReaderWriter::Options*>(options)); osgDB::ImageOptions* imageOptions = dynamic_cast<osgDB::ImageOptions*>(const_cast<osgDB::ReaderWriter::Options*>(options));
if (imageOptions) if (imageOptions)
@ -557,7 +557,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
(unsigned char *)imageData, (unsigned char *)imageData,
osg::Image::USE_NEW_DELETE); osg::Image::USE_NEW_DELETE);
if (texCoordRange) image->setUserData(texCoordRange); if (texCoordRange.valid()) image->setUserData(texCoordRange.get());
image->flipVertical(); image->flipVertical();
@ -593,7 +593,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
int destWidth = osg::minimum(dataWidth,4096); int destWidth = osg::minimum(dataWidth,4096);
int destHeight = osg::minimum(dataHeight,4096); int destHeight = osg::minimum(dataHeight,4096);
osgDB::ImageOptions::TexCoordRange* texCoordRange = 0; osg::ref_ptr<osgDB::ImageOptions::TexCoordRange> texCoordRange;
const osgDB::ImageOptions* imageOptions = dynamic_cast<const osgDB::ImageOptions*>(options); const osgDB::ImageOptions* imageOptions = dynamic_cast<const osgDB::ImageOptions*>(options);
if (imageOptions) if (imageOptions)