# Seg Fault vtkXMLMultiBlockDataSetWriter with vtkPolyData

**URL:** https://discourse.vtk.org/t/seg-fault-vtkxmlmultiblockdatasetwriter-with-vtkpolydata/237
**Category:** Support
**Created:** [February 7, 2019, 3:36am UTC](https://discourse.vtk.org/t/seg-fault-vtkxmlmultiblockdatasetwriter-with-vtkpolydata/237 "2019-02-07T03:36:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [February 7, 2019, 3:36am UTC](https://discourse.vtk.org/t/seg-fault-vtkxmlmultiblockdatasetwriter-with-vtkpolydata/237/1 "2019-02-07T03:36:01Z")

</div>

When I try to save a `vtkMultiBlockDataSet` that contains poly data that only has vertices, the `vtkXMLMultiBlockDataSetWriter` writer seg faults.

Below is a snippet to reproduce this segfault in Python. Does anyone know of a solution?

```python
import vtk
import numpy as np
from vtk.util import numpy_support as nps

npoints = 100
points = np.random.rand(npoints, 3)

# Make VTK cells array
cells = np.hstack((np.ones((npoints, 1)),
                   np.arange(npoints).reshape(-1, 1)))
cells = np.ascontiguousarray(cells, dtype=np.int64)
vtkcells = vtk.vtkCellArray()
vtkcells.SetCells(npoints, nps.numpy_to_vtk(cells, deep=True, array_type=vtk.VTK_ID_TYPE))

# Convert points to vtk object
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(npoints)
pts.SetData(nps.numpy_to_vtk(points))

# Create polydata
output = vtk.vtkPolyData()
output.SetPoints(pts)
output.SetVerts(vtkcells)

multi = vtk.vtkMultiBlockDataSet()
multi.SetNumberOfBlocks(1)
multi.SetBlock(0, output)

writer = vtk.vtkXMLMultiBlockDataWriter()
writer.SetFileName('foo.vtm')
writer.SetInputData(multi)

# AND THE SEG FAULT HAPPENS HERE
writer.Write()

```

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [February 9, 2019, 6:05am UTC](https://discourse.vtk.org/t/seg-fault-vtkxmlmultiblockdatasetwriter-with-vtkpolydata/237/2 "2019-02-09T06:05:58Z")

</div>

If I reshape a cells array into a one-dimensional array with reshape call, it works fine for me.

```python
# Make VTK cells array
cells = np.hstack((np.ones((npoints, 1)),
                   np.arange(npoints).reshape(-1, 1)))
cells = np.ascontiguousarray(cells, dtype=np.int64)
cells = np.reshape(cells, (2*npoints))

```

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [February 9, 2019, 6:32am UTC](https://discourse.vtk.org/t/seg-fault-vtkxmlmultiblockdatasetwriter-with-vtkpolydata/237/3 "2019-02-09T06:32:40Z")

</div>

> [@Kenichiro-Yoshimi](#):
>
> `cells = np.reshape(cells, (2*npoints))`

That totally fixes it! Any insights for why it needs to be this way?
