Segmentation effects crashing Slicer

Hello,
I’m using the preview version of Slicer to do a segmentation on a 2.6 GB micro-CT scan saved as a TIF. I can do a simple segmentation, but when I try to apply the mask or split volume effect, the Slicer application crashes. I’ve checked the error logs and there were no errors generated. I’m using a Windows machine with 32GB RAM and ~500GB free disk space.

I also generated the following warnings when trying to use the islands effect:

Slicer has caught an internal error.
You may be able to continue from this point, but results are undefined.
Suggested action is to save your work and restart.
If you have a repeatable sequence of steps that causes this message, please report the issue > > following instructions available at http://slicer.org
The message detail is:
Exception thrown in event: d:\d\p\slicer-0-build\itk\modules\core\common\include\itkImportImageContainer.hxx:199:
Failed to allocate memory for image.

and

Slicer has caught an internal error.
You may be able to continue from this point, but results are undefined.
Suggested action is to save your work and restart.
If you have a repeatable sequence of steps that causes this message, please report the issue following instructions available at http://slicer.org
The message detail is:
Exception thrown in event: bad allocation

I expected the amount of memory to be sufficient, but could this be the problem? Thanks for your advice.

It seems that you run out of memory. If you don’t expect this then maybe some extra memory allocations are performed or extents are computed incorrectly. You can add a breakpoint before itkImportImageContainer.hxx:199 and inspect variables to see if the memory that is attempted to be allocated have sensible size.

1 Like

Thanks @lassoan, I’ll try this.

After trying to load the dataset, I didn’t get a bad allocation. Instead I got a crash due to a lookup in scalar array using a negative index.

Code where the error occur is the following:

The crash occur when executing the line inScalars->GetComponent(idS++,0); with idS = -2147482744

It turns out that the idS ivar is of type int, and the value overflow … it should be changed to vtkIdType along with all intermediate variables.

The following snippet allows to reproduce the incorrect index value:

  int extent_0 = 0;
  int extent_1 = 1207;
  int extent_2 = 0;
  int extent_3 = 1250;
  int extent_4 = 0;
  int idY = 47;
  int idZ = 1421;

  int idS_test = ((extent_1 - extent_0 + 1)*
                   ((extent_3 - extent_2 + 1)*(idZ - extent_4) +
                    (idY - extent_2)));
  std::cout << "idS_test " << idS_test << std::endl;

  idY = 48;

  idS_test = ((extent_1 - extent_0 + 1)*
                     ((extent_3 - extent_2 + 1)*(idZ - extent_4) +
                      (idY - extent_2)));
  std::cout << "idS_test " << idS_test << std::endl;

associated output is:

idS_test 2147483344
idS_test -2147482744

Proposed path forward

To move forward,

We need to change the type of all intermediate variable to vtkIdType. The following work as expected:

  vtkIdType extent_0 = 0;
  vtkIdType extent_1 = 1207;
  vtkIdType extent_2 = 0;
  vtkIdType extent_3 = 1250;
  vtkIdType extent_4 = 0;
  vtkIdType idY = 47;
  vtkIdType idZ = 1421;

  vtkIdType idS_test = ((extent_1 - extent_0 + 1)*
                   ((extent_3 - extent_2 + 1)*(idZ - extent_4) +
                    (idY - extent_2)));
  std::cout << "idS_test " << idS_test << std::endl;

  idY = 48;

  idS_test = ((extent_1 - extent_0 + 1)*
                     ((extent_3 - extent_2 + 1)*(idZ - extent_4) +
                      (idY - extent_2)));
  std::cout << "idS_test " << idS_test << std::endl;

Output

idS_test 2147483344
idS_test 2147484552
1 Like

Here is the corresponding VTK merge request: https://gitlab.kitware.com/vtk/vtk/merge_requests/5816

2 Likes

Corresponding change has been integrated in Slicer as r28419

2 Likes

The mask/split volume effects are working now for my >2G images in the preview version. Thanks @jcfr!

2 Likes