From bd83044c08994c73e60c3e17c36915783f01bffb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 9 Jan 2019 08:38:16 +0000 Subject: [PATCH] Introduced use of ref_ptr<> and private destructor to tighen up memory management and avoid users attempting to inappropriately delete TexCoordRange. --- include/osgDB/ImageOptions | 2 ++ src/osgPlugins/gdal/ReaderWriterGDAL.cpp | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/osgDB/ImageOptions b/include/osgDB/ImageOptions index b54532084..21d8f3887 100644 --- a/include/osgDB/ImageOptions +++ b/include/osgDB/ImageOptions @@ -120,6 +120,8 @@ class OSGDB_EXPORT ImageOptions : public osgDB::Options } double _x,_y,_w,_h; + protected: + virtual ~TexCoordRange() {} }; diff --git a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp index 206476491..298e02fcc 100644 --- a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp +++ b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp @@ -142,7 +142,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter // int destHeight = osg::minimum(dataHeight,4096); - osgDB::ImageOptions::TexCoordRange* texCoordRange = 0; + osg::ref_ptr texCoordRange; osgDB::ImageOptions* imageOptions = dynamic_cast(const_cast(options)); if (imageOptions) @@ -557,7 +557,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter (unsigned char *)imageData, osg::Image::USE_NEW_DELETE); - if (texCoordRange) image->setUserData(texCoordRange); + if (texCoordRange.valid()) image->setUserData(texCoordRange.get()); image->flipVertical(); @@ -593,7 +593,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter int destWidth = osg::minimum(dataWidth,4096); int destHeight = osg::minimum(dataHeight,4096); - osgDB::ImageOptions::TexCoordRange* texCoordRange = 0; + osg::ref_ptr texCoordRange; const osgDB::ImageOptions* imageOptions = dynamic_cast(options); if (imageOptions)