[osg-users] Deleting osg::Image that is shallow copied

Robert Osfield robert.osfield at gmail.com
Tue Aug 16 04:21:26 PDT 2016

Hi Pierre-Jean,

The osg::Image constructor doesn't support shallow copy for the
internal image data, it will allocated a new image block and copy
across the data.  This means for the image data itself it's effective
a deep copy.

A shallow copy would be technically possible by would force one to
start reference counting the image data.  However, this doesn't make
any sense in the context of an osg::Image, if you want to share the
image data then you should be sharing the osg::Image object not the
internal data it holds.

My recommendation is not to do a shallow copy at all, but just share
the osg::Image.


On 16 August 2016 at 10:27, Pierre-Jean Petitprez
<pierre-jean.petitprez at inria.fr> wrote:
> Hi,
> In my application I have two osg::Images, the second one is a shallow copy of the first one thanks to the copy constructor.
> Is it safe to delete the first image and keep only the second one, or should I use deep copy instead?
> My tests showed me that the data is still reachable but when looking at the image destructor it clearly deallocates the data.
> Thanks for enlightening me,
> Cheers,
> Pierre-Jean
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68380#68380
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

More information about the osg-users mailing list