# Potential vtkUnstructuredGrid::ShallowCopy from vtkUnstructuredGridBase crash

**URL:** <https://discourse.vtk.org/t/potential-vtkunstructuredgrid-shallowcopy-from-vtkunstructuredgridbase-crash/9898>\
**Category:** Development\
**Created:** [November 20, 2022, 6:40pm UTC](https://discourse.vtk.org/t/potential-vtkunstructuredgrid-shallowcopy-from-vtkunstructuredgridbase-crash/9898 "2022-11-20T18:40:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bengt](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/f19dbf/32.png) [@Bengt](https://discourse.vtk.org/u/Bengt)\
**Post date:** [November 20, 2022, 6:40pm UTC](https://discourse.vtk.org/t/potential-vtkunstructuredgrid-shallowcopy-from-vtkunstructuredgridbase-crash/9898/1 "2022-11-20T18:40:32Z")

</div>

We’re using a `vtkMappedUnstructuredGrid` for our input data. One of our filters takes our type as input, adds data and is supposed to output a regular `vtkUnstructuredGrid`. We ran into a crash situation with this scenario because of the following:

At some point during pipeline execution the executive calls `vtkUnstructuredGrid::Initialize` when it prepares the filter output. This deletes the connectivity and types arrays. However, filters may then call `vtkUnstructuredGrid::ShallowCopy` in RequestData. This is a problem because there is special handling for `vtkUnstructuredGridBase` and the connectivity and type arrays are not recreated before a call to `vtkUnstructuredGrid::InternalInsertNextCell`, resulting in a crash.

For example this will crash:

```auto
// vtkUnstructuredGridBase subclass other than vtkUnstructuredGrid, e.g. vtkMappedUnstructuredGrid
vtkSmartPointer<vtkMyMappedGrid> source = ...; 
vtkNew<vtkUnstructuredGrid> ug;
ug->Initialize();
ug->ShallowCopy(source); // crashes

```

Are we using it wrong? Or am I correct that `vtkUnstructuredGrid::ShallowCopy` requires a check an potential allocation there?

Happy to prepare a fix if this turns out to be a bug.
