# ParaView 5.11 crashes when using vtkModifiedBSPTree in a python plugin

**URL:** https://discourse.paraview.org/t/paraview-5-11-crashes-when-using-vtkmodifiedbsptree-in-a-python-plugin/12495
**Category:** Development
**Tags:** vtk
**Created:** [July 11, 2023, 12:21pm UTC](https://discourse.paraview.org/t/paraview-5-11-crashes-when-using-vtkmodifiedbsptree-in-a-python-plugin/12495 "2023-07-11T12:21:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Loic](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/e9c0ed/32.png) [@Loic](https://discourse.paraview.org/u/Loic)
#### Post date: [July 11, 2023, 12:21pm UTC](https://discourse.paraview.org/t/paraview-5-11-crashes-when-using-vtkmodifiedbsptree-in-a-python-plugin/12495/1 "2023-07-11T12:21:33Z")

</div>

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:

```python
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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [July 20, 2023, 5:51pm UTC](https://discourse.paraview.org/t/paraview-5-11-crashes-when-using-vtkmodifiedbsptree-in-a-python-plugin/12495/2 "2023-07-20T17:51:16Z")

</div>

Cc: @mwestphal

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 24, 2023, 2:55pm UTC](https://discourse.paraview.org/t/paraview-5-11-crashes-when-using-vtkmodifiedbsptree-in-a-python-plugin/12495/3 "2023-07-24T14:55:39Z")

</div>

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