ParaView 5.11 crashes when using vtkModifiedBSPTree in a python plugin

Hi,

I’ve encountered a severe crash with a custom python filter in Paraview 5.11.1 on Windows 10.
This filter is based on a VTKPythonAlgorithmBase, which uses vtk.vtkModifiedBSPTree under the hood.

It seems that this crash occurs when the method IntersectWithLine is called.
I can reproduce this crash with the following code:

import numpy as np
import vtk
import vtk.numpy_interface.dataset_adapter as dsa

print('vtk :', vtk.VTK_VERSION)

# create a sphere
vf = vtk.vtkSphereSource()
vf.SetRadius(1)
vf.SetThetaResolution(32)
vf.SetPhiResolution(32)
vf.Update()
obj_sphere = vf.GetOutput()

# create a plan 
vf = vtk.vtkPlaneSource()
vf.SetOrigin([ 1, -1, 1])
vf.SetPoint1([-1, -1, 1])
vf.SetPoint2([ 1,  1, 1])
vf.SetXResolution(32)
vf.SetYResolution(32)
vf.Update()
obj_plan = vf.GetOutput()

# read plane coordinates
Pt = dsa.vtkDataArrayToVTKArray(obj_plan.GetPoints().GetData())  
nb_points = Pt.shape[0]

# Create a BSP Tree 
bspTree = vtk.vtkModifiedBSPTree()
bspTree.SetDataSet(obj_sphere)
bspTree.BuildLocator()

# Prepare intersectWithLine calls
tolerance = 0.00001
distMax   = 1+np.cos(np.pi/6)
dir_nor   = np.r_[0, 0, -1]

pList     = vtk.vtkPoints()
eList     = vtk.vtkIdList()

nb_arr = np.zeros(nb_points)

# get the number of intersections for each node
for i_m in range(nb_points):

    p1 = Pt[i_m]                
    p2 = p1 + distMax*dir_nor  

    eList.Reset()
    pList.Reset()

    if bspTree.IntersectWithLine(p1, p2, tolerance, pList, eList):
        nb_arr[i_m] = pList.GetNumberOfPoints()
    else :
        nb_arr[i_m] = 0

# save results
obj_plan.GetPointData().AddArray(dsa.numpyTovtkDataArray( nb_arr, 'nb'))
vf = vtk.vtkXMLPolyDataWriter() 
vf.SetFileName('test_IntersectWithLine.vtp')
vf.SetInputDataObject(obj_plan)
vf.Update()
print('Write test_IntersectWithLine.vtp')

I’ve run several tests with that code :

  • When I run that code in Paraview 5.11.1, Paraview crashes without traceback before saving results.
    I’tried to run that code with pvbatch.exe with the --enable-bt option, but I did’nt get any additionnal information.

  • When I run that code in Paraview 5.10, it runs without error.

  • When I run that code in a python console with vtk 9.2.6 from PyPI, it runs also without error.

Are there any special precaution to take to use vtk from a python plugin in paraview 5.11?
Should I create a bug in the ParaView issue tracker?

Cc: @mwestphal

Fixed in master and the upcoming 5.12. You can try with the nightly: https://www.paraview.org/download/?version=nightly