Slicer crashes when creating scalar volume node

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:

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

  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)

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

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

We have fixed this crash some time ago. 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.