[Dcmlib] [Gdcm2] Assertion failed: ReferenceCount == 0

Mathieu Malaterre mathieu.malaterre at gmail.com
Sun Aug 31 01:03:04 CEST 2008


The real issue is the well known problem of ownership in C++. If you
know what you are doing and would like a copy of the image (shallow
copy of the image), then the correct syntax is:

  const Image& img = reader.GetImage();
  SmartPointer<Image> copy = img;

When copy will go out of scope it will get deleted. The designed of
the smart pointer was largely inspired by the one in ITK, except that
*everything* in ITK derive from a common Object parent class. So code
are very consistent and people just copy everything aruond using smart
pointer. I have designed this dual syntax in GDCM, where some object
can be allocated on the stack, while the one designed to being used
via the SmartPointer implementation are not.

  I either need to *seriously* update the documentation, and/or make
sure that no derive class from Object can be allocated on the stack.

Sorry for trouble.

-Mathieu

On Sat, Aug 30, 2008 at 1:58 PM, Greg Book <gbook at gbook.org> wrote:
> I encountered the exact same problem. I used "const Image& img =
> reader.GetImage()" but... I need to load files in a loop and I can't modify
> a const once its created. Any way around this?
> Thanks,
> Greg
>
>
> Mathieu Malaterre wrote:
>
> Oooops
>
> On Wed, Aug 27, 2008 at 7:11 PM, Matthias Sweertvaegher
> <matthias.sweertvaegher at uz.kuleuven.ac.be> wrote:
>
>
>
>  Image img = imgReader.GetImage();
>
>
> Nope, in fact that is the line that is causing the crash sorry for the
> noise. Please replace for now with:
>
> const Image& img = imgReader.GetImage();
>
> And please, fill in a bug report.
>
> Thanks,
>
>
> _______________________________________________
> Dcmlib mailing list
> Dcmlib at creatis.insa-lyon.fr
> http://www.creatis.insa-lyon.fr/mailman/listinfo/dcmlib
>



-- 
Mathieu



More information about the Dcmlib mailing list