I’m running into an odd error that I can’t seem to figure out the reason behind. With the following code I get a crash when compiling release mode, but it runs totally fine in debug mode.
I’m working with vtk 9.2 libraries. I’ll compile the latest to see if this is also an issue, however I’m version limited on the system this will be deployed to.
vtkNew<vtkUnstructuredGrid> test_grid;
test_grid->SetPoints(vtkSmartPointer<vtkPoints>::New());
test_grid->GetPoints()->InsertNextPoint(0., 0., 0.);
test_grid->GetPoints()->InsertNextPoint(1., 0., 0.);
test_grid->GetPoints()->InsertNextPoint(1., 1., 0.);
test_grid->GetPoints()->InsertNextPoint(0., 1., 0.);
const vtkIdType pntsIds[] = {0,1,2,3};
test_grid->InsertNextCell(VTK_POLYGON, 4, pntsIds);
vtkSmartPointer<vtkFloatArray> scalar = vtkSmartPointer<vtkFloatArray>::New();
scalar->SetName("field_value1");
scalar->InsertNextValue(5);
test_grid->GetCellData()->AddArray(scalar); //Crashes here
The crash inside of vtk seems to originate here:
void vtkFieldData::AllocateArrays(int num)
{
...
}
else // num > this->NumberOfArrays
{
vtkAbstractArray** data = new vtkAbstractArray*[num];
this->Ranges.resize(num);
this->FiniteRanges.resize(num); //<<--- Here
Basically all the variables of this
instance are garbage (Ranges, FiniteRanges, NumberOfArrays
, etc.)
When compiled in debug mode, these are all empty/0.
I’m stumped. Can anyone suggest where to look?