[Insight-developers] how to detect pixel allocation failure ?
Simon Warfield
warfield at crl.med.harvard.edu
Wed Mar 15 12:09:48 EST 2006
I have some code that runs fine on a 64 bit workstation but fails with a
segmentation fault on a 32 bit workstation.
It turns out this code is allocating a 4D image of size 256x256x40x208
pixels.
The code fails in a call to FillBuffer(0) when after a certain number of
pixels (*m_Buffer)[i] stops being a valid container.
> Size of the LargestPossibleRegion
> 256 256 46 208
> About to call W->FillBuffer(0)
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread -1208133952 (LWP 5008)]
> 0x080ea098 in itk::Image<double, 4u>::FillBuffer (this=0x981d730,
> value=@0xbfe998b8)
> at
> /opt/i386/pkgs/itk/2.4.1/gcc-release/include/InsightToolkit/Common/itkImage.txx:83
> 83 (*m_Buffer)[i] = value;
> (gdb) print i
> $1 = 90178047
The buffer is allocated through AllocateOutputs() which ultimately calls
itk::ValarrayImageContainer<TElementIdentifier, TElement>::Reserve()
It turns out that Reserve() is not guaranteed to allocate the pixels as
requested. The documentation says Reserve does the following:
> Tell the container to allocate enough memory to allow at least as many
> elements as the size given to be stored. This is NOT guaranteed to
> actually allocate any memory, but is useful if the implementation of
> the container allocates contiguous storage. Definition at line 112
> <http://www.itk.org/Doxygen/html/itkValarrayImageContainer_8h-source.html#l00112>
> of file itkValarrayImageContainer.h
> <http://www.itk.org/Doxygen/html/itkValarrayImageContainer_8h-source.html>.
The API for itk::Image->Allocate() is for Allocate() to return void,
whether or not allocate succeeds.
I wonder if it should instead return a boolean indicating success or
failure of the Allocate() operation ?
Is there some other means to determine if Allocate() was successful ?
--
Simon
More information about the Insight-developers
mailing list