# Crash when configuration conflict (library debug & vtk release)

**URL:** https://discourse.vtk.org/t/crash-when-configuration-conflict-library-debug-vtk-release/14984
**Category:** Support
**Tags:** code
**Created:** [December 9, 2024, 8:42am UTC](https://discourse.vtk.org/t/crash-when-configuration-conflict-library-debug-vtk-release/14984 "2024-12-09T08:42:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pcristini](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pcristini](https://discourse.vtk.org/u/pcristini)
#### Post date: [December 9, 2024, 8:42am UTC](https://discourse.vtk.org/t/crash-when-configuration-conflict-library-debug-vtk-release/14984/1 "2024-12-09T08:42:51Z")

</div>

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.

```C++
	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:

```C++
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?

---

<div class="post-metadata">

### Author: ![pcristini](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pcristini](https://discourse.vtk.org/u/pcristini)
#### Post date: [December 9, 2024, 10:20am UTC](https://discourse.vtk.org/t/crash-when-configuration-conflict-library-debug-vtk-release/14984/2 "2024-12-09T10:20:22Z")

</div>

A bit of further information I just discovered.

The crash appears to be an issue between the Release/Debug compilation. Below table represents what I’ve been able to reproduce.

| my\_library | vtk | crash? |
| --- | --- | --- |
| debug | debug | 0 |
| release | debug | 1 |
| debug | release | 1 |
| release | release | 0 |

Can anyone give reasoning why this is happening?

In order to resolve this I would have to have both debug and release versions of the vtk libraries when developing. Which, for me is no issue, but for the others on my team who won’t be touching this part of the code it’s a bit of a pain to manage.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 3, 2025, 9:55pm UTC](https://discourse.vtk.org/t/crash-when-configuration-conflict-library-debug-vtk-release/14984/3 "2025-03-03T21:55:49Z")

</div>

Release and Debug builds use different C++ runtime implementations on Windows. You might try using the “RelWithDebInfo” instead of Debug which will have some debug information while also using the release runtime. Alternatively, you can set [`CMAKE_MSVC_RUNTIME_LIBRARY`](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html) to be consistent between the builds regardless of the configuration selection.
