# Slicer crashes when creating scalar volume node

**URL:** <https://discourse.slicer.org/t/slicer-crashes-when-creating-scalar-volume-node/29302>\
**Category:** Support\
**Created:** [May 5, 2023, 9:06am UTC](https://discourse.slicer.org/t/slicer-crashes-when-creating-scalar-volume-node/29302 "2023-05-05T09:06:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnzzll](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nnzzll/32/16350_2.png) [@nnzzll](https://discourse.slicer.org/u/nnzzll)\
**Post date:** [May 5, 2023, 9:06am UTC](https://discourse.slicer.org/t/slicer-crashes-when-creating-scalar-volume-node/29302/1 "2023-05-05T09:06:57Z")

</div>

I try to create a `vtkMRMLScalarVolumeNode` by calling `slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")`, but slicer crashed after calling this method.

Messages below are output of terminal:

```auto
Input port 0 of algorithm vtkImageThreshold(0x562d37c530a0) has 0 connections but is not optional.

Input port 0 of algorithm vtkImageMapToWindowLevelColors(0x562d37c696f0) has 0 connections but is not optional.

Input port 0 of algorithm vtkImageMapToWindowLevelColors(0x562d37c696f0) has 0 connections but is not optional.

Input port 0 of algorithm vtkImageThreshold(0x562d37c530a0) has 0 connections but is not optional.

Input port 0 of algorithm vtkImageMapToWindowLevelColors(0x562d37c696f0) has 0 connections but is not optional.

Segmentation fault (core dumped)

```

I used gdb to debug the program and found that Slicer crashed at `build/VTK/Rendering/OpenGL2/vtkOpenGLImageMapper.cxx:616`

```auto
  switch (data->GetPointData()->GetScalars()->GetDataType())

```

`data->GetPointData()->GetScalars()` returns a nullptr which triggered the segmentation fault.

How can I fix this problem? It works fine on Windows but crashes everytime on my ubuntu desktop.

OS: ubuntu 18.04  
Slicer Version:5.0.3 (7ea0f439e837fca8c92a315fb0b2a9b0ff28e1e4)

---

<div class="post-metadata">

**Author:** ![pearsonm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pearsonm/32/18514_2.png) [@pearsonm](https://discourse.slicer.org/u/pearsonm)\
**Post date:** [May 5, 2023, 11:25pm UTC](https://discourse.slicer.org/t/slicer-crashes-when-creating-scalar-volume-node/29302/2 "2023-05-05T23:25:26Z")

</div>

Can you show more of the code? That call works as expected on my ubuntu 22.04 machine.

---

<div class="post-metadata">

**Author:** ![nnzzll](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nnzzll/32/16350_2.png) [@nnzzll](https://discourse.slicer.org/u/nnzzll)\
**Post date:** [May 6, 2023, 1:26am UTC](https://discourse.slicer.org/t/slicer-crashes-when-creating-scalar-volume-node/29302/3 "2023-05-06T01:26:38Z")

</div>

There is no more code.  
Just start a Slicer program and type `slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")` in the python interactor, then Slicer crashes.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 6, 2023, 5:09pm UTC](https://discourse.slicer.org/t/slicer-crashes-when-creating-scalar-volume-node/29302/4 "2023-05-06T17:09:32Z")

</div>

We have [fixed this crash some time ago](https://github.com/Slicer/Slicer/issues/6381). Please use current version of Slicer.

That said, while we try to add safety checks everywhere in the code, if you use the API in unexpected ways (in this case, create a volume node and not set image data in it) then problems may occur. Feel free to keep reporting these, as we can make the API more robust based on these feedbacks.
