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

Pierre-Jean Petitprez pierre-jean.petitprez at inria.fr
Tue Aug 16 04:27:40 PDT 2016


Hi Robert and Christian,

Thank you for your answers.  Now I understand why my expectations on 
using the shallow copy were not working.
So I will just share the same osg::Image.
Also thanks for pointing out the allocation mode, it can be very useful 
if I want to manually manage the _data pointer.

Thanks for your help,

Cheers
Pierre-Jean

Le 16/08/2016 à 13:21, Robert Osfield a écrit :
> 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.
>
>
> Robert.
>
> 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
> _______________________________________________
> 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