vtkStripper segfaults in presence of zero-extent lines
vtkStripper
sometimes crashes with a segmentation fault for lines with zero-extent. I did not find a reliable pattern to reproduce this problem in 100%. But on my machine, the seg-fault occurred in 70-80% of the times.
The problem may generalize to other input as well.
System: MacOS 10.14.5 VTK: 8.1.2
import vtk
import numpy as np
p = vtk.vtkPoints()
p.InsertNextPoint(np.random.rand(3))
p.InsertNextPoint(np.random.rand(3))
p.InsertNextPoint(np.random.rand(3))
c = vtk.vtkCellArray()
cell = vtk.vtkLine()
cell.GetPointIds().SetId(0,0)
cell.GetPointIds().SetId(1,1)
c.InsertNextCell(cell)
cell = vtk.vtkLine()
cell.GetPointIds().SetId(0,1)
cell.GetPointIds().SetId(1,2)
c.InsertNextCell(cell)
cell = vtk.vtkLine()
cell.GetPointIds().SetId(0,2)
cell.GetPointIds().SetId(1,0)
c.InsertNextCell(cell)
# This is the culprit - a line with zero extent.
# Just adding this line (and not the three other lines),
# will not lead to the exception. Only the presence of
# valid lines and zero-extent lines cause a problem.
cell = vtk.vtkLine()
cell.GetPointIds().SetId(0,0) # Start and end point
cell.GetPointIds().SetId(1,0) # are the same (pId=0)
c.InsertNextCell(cell)
poly = vtk.vtkPolyData()
poly.SetPoints(p)
poly.SetLines(c)
s = vtk.vtkStripper()
s.SetInputData(poly)
s.Update() # The crash is produced here.
Here is a typical stack trace for the segfault.
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libvtkCommonDataModel-8.1.1.dylib 0x0000000102b22490 vtkPolyData::GetPointCells(long long, vtkIdList*) + 192
1 libvtkFiltersCore-8.1.1.dylib 0x000000010329b15b vtkStripper::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 6779
2 libvtkCommonExecutionModel-8.1.1.dylib 0x0000000102ed1275 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 69
3 libvtkCommonExecutionModel-8.1.1.dylib 0x0000000102ecbb5d vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 61
4 libvtkCommonExecutionModel-8.1.1.dylib 0x0000000102ec741b vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 107
5 libvtkCommonExecutionModel-8.1.1.dylib 0x0000000102ecb2f7 vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1175
6 libvtkCommonExecutionModel-8.1.1.dylib 0x0000000102ef1a1b vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 539
7 libvtkCommonExecutionModel-8.1.1.dylib 0x0000000102ef1f9b vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 283
8 libvtkCommonExecutionModelPython36D-8.1.1.dylib 0x0000000102e34f23 PyvtkAlgorithm_Update(_object*, _object*) + 387
9 org.python.python 0x000000010141d7cb _PyCFunction_FastCallDict + 491
10 org.python.python 0x000000010149f747 call_function + 439
11 org.python.python 0x000000010149beb7 _PyEval_EvalFrameDefault + 27559
12 org.python.python 0x00000001014a01af _PyEval_EvalCodeWithName + 2447
13 org.python.python 0x0000000101495244 PyEval_EvalCode + 100
14 org.python.python 0x00000001014cb381 PyRun_FileExFlags + 209
15 org.python.python 0x00000001014cabf2 PyRun_SimpleFileExFlags + 882
16 org.python.python 0x00000001014e4b12 Py_Main + 3554
17 org.python.python 0x00000001013c3df8 0x1013c3000 + 3576
18 libdyld.dylib 0x00007fff681083d5 start + 1
Edited by Norman Specificus