Problem with DcmFileFormat::clone()

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Problem with DcmFileFormat::clone()

#1 Post by st80rules »

Hi,

I have a problem copying DcmFileFormat objects. The problem is kind of difficult to explain:

- my app has a plugin architecture, a la photoshop
- the image loading code is in a plugin (a dll)
- the dll loads an image file DcmFileFormat::loadFile()
- it then passes the DcmFileFormat object to a COM library (another dll)
- that dll copies the DcmFileFormat (because it needs to hang on to it)

Then all kinds of memory related problems occur when I try to manipulate the copied DcmFileFormat object. AFAICT, it seems that portions of the deep copy are not deep copied, thus resulting in heap errors. I tried the clone() method, and the copyFrom() method, and both exhibit the problem.

If I serialize the DcmFileFormat object between the two spaces, then all is good (which would seem to confirm my theory). The problem with that approach is that serialization is very slow (especially de-serialization).

I'm using a 3.6.1 July 27th 2012 snapshot.

How can I solve this issue? Does this ring a bell with anyone?

Thanks

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Problem with DcmFileFormat::clone()

#2 Post by st80rules »

Oh, if it's any help, the problem seems to be related to sequences.

For example, this will fail in the COM dll:

DcmFileFormat* copiedData = (DcmFileFormat*)sourceFF->clone();
DcmTagKey tag(24, 49);
const char* sValue = NULL;
OFCondition cond = copiedData->getDataset()->fingAndGetString(tag, sValue, OFTrue);

but this won't:

OFCondition cond = copiedData->getDataset()->fingAndGetString(tag, sValue, OFFalse);

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Problem with DcmFileFormat::clone()

#3 Post by J. Riesmeier »

What happens if you print() the copied dataset/fileformat or if you save it to file? I mean when you compare the copied data structure with the "original" one.

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Problem with DcmFileFormat::clone()

#4 Post by st80rules »

Maybe I wasn't clear in my original posting, the problem is not with the results, the problems is that clone()ing a DcmFileFormat induces heap related memory errors as soon as I try manipulating sequences. And I mean cloning in two different "contexts", i.e. two different dlls.

If I transmit the DcmFileFormat through serialization, then I don't encounter those memory problems.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Problem with DcmFileFormat::clone()

#5 Post by J. Riesmeier »

This is just a wild guess, but maybe the DcmTag references (inside the DcmObject instances) to the global data dictionary are the reason for your problems!? But then it should also occur when no sequences are contained in the dataset. I just checked the code, and the copy constructor of DcmTag looks ok to me ... at first glance.

Btw, there is no "3.6.1 July 27th 2012 snapshot" of DCMTK. Did you use the official shared library (DLL) support from DCMTK?

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Problem with DcmFileFormat::clone()

#6 Post by st80rules »

Well the problem always occurs when deleting DcmStackNode instances (from the DcmStack destructor), so no it's not related to DcmTag instances.

The so-called snapshot I'm using was sent from someone at Offis (as it included the DcmPrint module). And no I'm not using shared dll mode, all my app is build using the static link mode (/MT) under Windows.

Tim
Posts: 17
Joined: Wed, 2009-04-29, 10:08
Location: Zaragoza
Contact:

Re: Problem with DcmFileFormat::clone()

#7 Post by Tim »

Hi there

I've had pretty bad experiences in the past when linking with DLLs which have been solved by ensuring you use the same build settings for all the DLLs and EXEs, so I would strongly recommend looking at that (if you control all the DLLs !). Truth is, I can't remember the details now...

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest