# Error with inserting vertex cells

**URL:** https://discourse.vtk.org/t/error-with-inserting-vertex-cells/750
**Category:** Support
**Created:** [April 12, 2019, 1:20pm UTC](https://discourse.vtk.org/t/error-with-inserting-vertex-cells/750 "2019-04-12T13:20:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Frank](https://discourse.vtk.org/user_avatar/discourse.vtk.org/frank/32/43_2.png) [@Frank](https://discourse.vtk.org/u/Frank)
#### Post date: [April 12, 2019, 1:20pm UTC](https://discourse.vtk.org/t/error-with-inserting-vertex-cells/750/1 "2019-04-12T13:20:08Z")

</div>

I want to create a `polyData` with lots of vertex. So I followed [example](https://vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Vertex)

```auto
auto vertexes = vtkSmartPointer<vtkCellArray>::New();
for (int i = 0; i < data->GetNumberOfPoints(); i++) {
    auto vertex = vtkSmartPointer<vtkVertex>::New();
    vertex->GetPointIds()->SetId(i, i);
    vertexes->InsertNextCell(vertex);
}
dataPoints->SetPoints(points);
dataPoints->SetVerts(vertexes);

```

This cause an error.

```auto
(gdb) bt
#0 0x00005564b54e5b68 in vtkCellArray::InsertNextCell (this=0x5564b5fea4b0, npts=1, pts=0x5564b62d8630) at /usr/local/include/vtk-8.2/vtkCellArray.h:304
#1 0x00005564b54e5c2a in vtkCellArray::InsertNextCell (this=0x5564b5fea4b0, cell=0x5564b60029c0) at /usr/local/include/vtk-8.2/vtkCellArray.h:345
#2 0x00005564b54e555f in main () at /home/wzx/CLionProjects/propeller_surface_reconstruction/main.cpp:39
#3 0x00007fb6d33c4223 in __libc_start_main () from /usr/lib/libc.so.6
#4 0x00005564b54e526e in _start ()

```

The following code performed well.

```auto
auto vertexes = vtkSmartPointer<vtkCellArray>::New();
for (int i = 0; i < data->GetNumberOfPoints(); i++) {
    vtkIdType pid[1];
    pid[0] = i;
    vertexes->InsertNextCell(1, pid);
}
dataPoints->SetPoints(points);
dataPoints->SetVerts(vertexes);

```

Why?

---

<div class="post-metadata">

### Author: ![Aron\_Helser](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aron_helser/32/14_2.png) [@Aron\_Helser](https://discourse.vtk.org/u/Aron_Helser)
#### Post date: [April 12, 2019, 1:50pm UTC](https://discourse.vtk.org/t/error-with-inserting-vertex-cells/750/2 "2019-04-12T13:50:36Z")

</div>

It’s because of this line:

```auto
vertex->GetPointIds()->SetId(i, i);

```

```auto
I believe it should be

```

```auto

```

vertex-\>GetPointIds()-\>SetId(0, i);

```auto
You are adding a single vertex to each cell, and the cell only refers to a single point. So the cell's only ID should refer to point 'i' in the points list.

```

This is done automatically in your second code fragment.

```auto

```

HTH,

```auto

```

Aron

```auto

```

---

<div class="post-metadata">

### Author: ![Frank](https://discourse.vtk.org/user_avatar/discourse.vtk.org/frank/32/43_2.png) [@Frank](https://discourse.vtk.org/u/Frank)
#### Post date: [April 12, 2019, 1:56pm UTC](https://discourse.vtk.org/t/error-with-inserting-vertex-cells/750/3 "2019-04-12T13:56:38Z")

</div>

I am very careless about this. Thank you for your help.
