putFloat32 segmentation fault

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
spasmous
Posts: 31
Joined: Mon, 2009-02-02, 19:19

putFloat32 segmentation fault

#1 Post by spasmous »

I'm having trouble inserting a float32 into a DcmFloatingPointSingle array.

Code: Select all

size_t n =12;
DcmFloatingPointSingle dcm_Fl32(DcmTagKey(0x0043,0x1038),n); 
for (j=0; j<n; j++)
{
   Float32 myval;

   dcm_Fl32.getFloat32(myval,j);
   printf("%i %f\n",j,myval);
	
   dcm_Fl32.putFloat32(999.,j);
   printf("HELLO\n");

   dcm_Fl32.getFloat32(myval,j);
   printf("%i %f\n\n",j,myval);
}
The output I see when executing is:

0 0.000000
Segmentation fault

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

Re: putFloat32 segmentation fault

#2 Post by J. Riesmeier »

Which version of the DCMTK are you using?

Btw, the "len" parameter in the DcmFloatingPointSingle constructor takes the length in bytes and not the number of values (VM). And, there is also a putFloat32Array() method ...

Xiao
Posts: 36
Joined: Wed, 2011-05-25, 07:53

Re: putFloat32 segmentation fault

#3 Post by Xiao »

I wonder that you want to write a element with DICOM (OF) VR, if so, you can use DcmOtherFloat class. a class representing the DICOM value representation 'Other Float String' (OF)

spasmous
Posts: 31
Joined: Mon, 2009-02-02, 19:19

Re: putFloat32 segmentation fault

#4 Post by spasmous »

J. Riesmeier wrote:Which version of the DCMTK are you using?

Btw, the "len" parameter in the DcmFloatingPointSingle constructor takes the length in bytes and not the number of values (VM). And, there is also a putFloat32Array() method ...
Version 3.6.0. Compiled on both gcc 3.3 and 3.4 with same result (I know, slightly old versions).

Thanks for the clue about "len". I added a sizeof(Float32) in my code, makes no difference to the seg fault. I was using putFloat32Array for a while but decided I didn't want a Float32 array hanging around just to pass to putFloat32Array. I can always go back if putFloat32 "doesn't work".

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

Re: putFloat32 segmentation fault

#5 Post by J. Riesmeier »

Could you please try to construct the DcmFloatingPointSingle with len=0 and then call putFloat32() in increasing order of the pos parameter, i.e. 0, 1, 2, ... This is because (taken from the API documentation of DcmElement):

Code: Select all

     *  @param pos position for insert operation. Value: pos <= getVM(), i.e. a value
     *    can be appended to the end of the current element or inserted within the
     *    existing value field.
    [...]
    virtual OFCondition putFloat32(const Float32 val, const unsigned long pos = 0);

spasmous
Posts: 31
Joined: Mon, 2009-02-02, 19:19

Re: putFloat32 segmentation fault

#6 Post by spasmous »

J. Riesmeier wrote:Could you please try to construct the DcmFloatingPointSingle with len=0 and then call putFloat32() in increasing order of the pos parameter, i.e. 0, 1, 2, ...
Yes, that works. Thank you!

So it seems there is only a problem if the array length is declared with the constructor. I double checked (putting 100000 as the 2nd argument) and the seg fault reappeared.

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

Re: putFloat32 segmentation fault

#7 Post by J. Riesmeier »

Yes, because internally the length value passed to the constructor is stored, but the memory is not allocated.

Post Reply

Who is online

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