# QVTKWidgetPlugin destructed after ctreating a polydata

**URL:** https://discourse.slicer.org/t/qvtkwidgetplugin-destructed-after-ctreating-a-polydata/20890
**Category:** Support
**Tags:** vtk, python
**Created:** [December 2, 2021, 7:06pm UTC](https://discourse.slicer.org/t/qvtkwidgetplugin-destructed-after-ctreating-a-polydata/20890 "2021-12-02T19:06:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dalbenzioG](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dalbenziog/32/16834_2.png) [@dalbenzioG](https://discourse.slicer.org/u/dalbenzioG)
#### Post date: [December 2, 2021, 7:06pm UTC](https://discourse.slicer.org/t/qvtkwidgetplugin-destructed-after-ctreating-a-polydata/20890/1 "2021-12-02T19:06:51Z")

</div>

Hello,

I created the following function that should generate a polydata out of x, y, and z coordinate of points.

```auto
def createPolyData(x , y , z , maxNumPoints=1e6) :
    data = np.column_stack((x.ravel() , y.ravel() , z.ravel()))

    polyPoints = vtk.vtkPoints()
    vtkDepth = vtk.vtkDoubleArray()
    vtkCells = vtk.vtkCellArray()
    vtkPolyData = vtk.vtkPolyData()

    for k in range(size(data , 0)) :
        point = data[k]

        if polyPoints.GetNumberOfPoints() < maxNumPoints :
            pointId = polyPoints.InsertNextPoint(point[:])
            vtkDepth.InsertNextValue(point[2])
            vtkCells.InsertNextCell(1)
            vtkCells.InsertCellPoint(pointId)
            vtkCells.Modified()
            polyPoints.Modified()
            vtkDepth.Modified()
    vtkPolyData.SetPoints(polyPoints)
    vtkPolyData.SetVerts(vtkCells)
    vtkDepth.SetName('Distance')
    vtkPolyData.GetPointData().SetScalars(vtkDepth)
    vtkPolyData.GetPointData().SetActiveScalars('Distance')

    return vtkPolyData

```

The attached picture is obtained after rendering that polydata in vtk using the createPolyData function  
 ![pointsefd](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/a/caa602c5d287b6a70990ab4b94c3627a11f1af6f.png)  
When I try to display the same polydata in 3DSlicer I encounter the following error : **QVTKWidgetPlugin destructed** after getting the output polydata and, after a while, Slicer crash.

So far I have no clue how to solve this problem. Do you have any feedback?  
I hope I have been able to explain clearly my problem otherwise, I will be happy to give you more details.  
Thank you 🙏

Operating System: Ubuntu 20.04.3 LTS  
Slicer Version : 4.13.0 r30429 / 00d2939

---

<div class="post-metadata">

### Author: ![dalbenzioG](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dalbenziog/32/16834_2.png) [@dalbenzioG](https://discourse.slicer.org/u/dalbenzioG)
#### Post date: [February 10, 2022, 8:32am UTC](https://discourse.slicer.org/t/qvtkwidgetplugin-destructed-after-ctreating-a-polydata/20890/2 "2022-02-10T08:32:37Z")

</div>

Updating Slicer has fixed the problem 🙂
