Build error C4996 in vtkUnstructuredGrid.h after Visual Studio update (VTK 9.6)

OS: Windows 11

VTK Version: 9.6

Compiler: Visual Studio Professional 2026 (v18.7.1)

Hi everyone,

Since updating Visual Studio to the latest version, my C++ project using VTK 9.6 has stopped compiling. I am encountering the following build error:

Common\DataModel\vtkUnstructuredGrid.h(134,8): error C4996: ‘vtkDataSet::GetCellTypes’: Use GetDistinctCellTypes(vtkCellTypes* types) instead.

searched my entire project but could not find any explicit calls to GetCellTypes in my code, so I suspect this warning/error is originating internally from another VTK file.

The only part of my codebase that utilizes vtkUnstructuredGrid is the following snippet, which makes me think the issue might be triggered when interacting with vtkGeometryFilter:

`auto plusSource = vtkSmartPointer<vtkGlyphSource2D>::New();
plusSource->SetGlyphTypeToCross();
m_glyphSources.insert({ GlyphTypes::Plus, plusSource });

std::vector<std::array<double, 3>> truncPyramidCoord;
truncPyramidCoord.push_back({ {-0.5, -0.5, 0.0} }); // Bottom Face
truncPyramidCoord.push_back({ {0.5, -0.5, 0.0} });
truncPyramidCoord.push_back({ {0.5, 0.5, 0.0} });
truncPyramidCoord.push_back({ {-0.5, 0.5, 0.0} });
truncPyramidCoord.push_back({ {-0.3, -0.3, 1.0} }); // Top Face
truncPyramidCoord.push_back({ {0.3, -0.3, 1.0} });
truncPyramidCoord.push_back({ {0.3, 0.3, 1.0} });
truncPyramidCoord.push_back({ {-0.3, 0.3, 1.0} });
vtkNew<vtkPoints> truncPyramidPoints;
vtkNew<vtkHexahedron> hexahedron;
for (auto i = 0; i < truncPyramidCoord.size(); ++i)
{
	truncPyramidPoints->InsertNextPoint(truncPyramidCoord[i].data());
	hexahedron->GetPointIds()->SetId(i, i);
}
vtkNew<vtkUnstructuredGrid> truncPyramidUGrid;
truncPyramidUGrid->SetPoints(truncPyramidPoints);
truncPyramidUGrid->InsertNextCell(hexahedron->GetCellType(), hexahedron->GetPointIds());
auto truncated_pyramid = vtkSmartPointer<vtkGeometryFilter>::New();
truncated_pyramid->SetInputData(truncPyramidUGrid);
m_glyphSources.insert({ GlyphTypes::TruncatedPyramid, truncated_pyramid });`

As workarounds, I have already tried adding #define VTK_LEGACY_SILENT at the very top of my source (.cpp) files, my engine header file before any other include directives. Unfortunately, the error persists.

Has anyone encountered this problem recently with the latest MSVC updates, and is there a known fix or workaround for it?

Thank you in advance for your help!
C.R.

@spyridon97 wdyt ?

@CharInt0 did you rebuild VTK yourself using the same compiler ?

No, I am using a pre-compiled version of VTK 9.6 that was built with an older version of Visual Studio.

Since I just updated my local Visual Studio to version 18.7.1, my project is using the new compiler, but it is still pointing to those older VTK binaries and include paths.

Do I need to completely clear my build directory and rebuild the VTK source code from scratch using this new version of Visual Studio to fix the error?

While I cannot ensure it will fix the error, this is where I would start.

I have no clue what could have caused that. I suggest building from source.

Mathieu and Spiros Tsalikis, thank you for the suggestions.

I completely wiped my build directory and did a fresh build of the VTK 9.6 source code from scratch using the new Visual Studio 2026 compiler toolset (MSVC 18.7.8.30822, targeting x64).

The CMake configuration and generation completed successfully, Then the VTK 9.6 actually compiled successfully too with the new compiler toolset. However, when I tried to recompile my project, which links dynamically to the newly built VTK libraries, the build failed with the same error:

1>C:\VTK\VTK-src\Common\DataModel\vtkUnstructuredGrid.h(134,8): error C4996: 'vtkDataSet::GetCellTypes': Use GetDistinctCellTypes(vtkCellTypes* types) instead.

Even though I rebuilt VTK with the same compiler, whenever my project includes vtkUnstructuredGrid.h, the compiler treats the deprecated GetCellTypes warning as a hard error. As mentioned before, adding #define VTK_LEGACY_SILENT in my project headers or precompiled headers (pch.h) did not bypass it.

Sounds like a bug in VTK with VS 2026, please open an issue: https://gitlab.kitware.com/paraview/paraview/-/work_items

So i see something that may be problematic

both classes deprecate the same function, and implement it the same way.

Could you try to remove the function definition and deprecation of GetCellTypes from vtkUnstructuredGrid.h
recompile and tell us if it fixed the error?

I followed your suggestion and commented out the deprecated function definition from vtkUnstructuredGrid.h like this:

C++

// VTK_DEPRECATED_IN_9_6_0("Use GetDistinctCellTypes(vtkCellTypes* types) instead.")
// void GetCellTypes(vtkCellTypes* types) override { this->GetDistinctCellTypes(types); }

After doing this and recompiling VTK 9.6, my project now compiles successfully without any errors. The conflict between the duplicate deprecations in vtkDataSet and vtkUnstructuredGrid was definitely what was causing the MSVC 18.7.8 compiler to trigger the hard C4996 error in the client solution.

For some unknown reason now I cannot open open a bug report on the Kitware GitLab repository, the site is hanging after I click “create”.

Thank you all so much for your help,
C.R.

click here, https://gitlab.kitware.com/ after that it should work.

Thank you Mathieu. It worked:

VTK 9.6 build error C4996 in vtkUnstructuredGrid.h with MSVC 18.7.8 (GetCellTypes deprecation conflict)

paraview/paraview#23314

moved to https://gitlab.kitware.com/vtk/vtk/-/work_items/20091

Fix in https://gitlab.kitware.com/vtk/vtk/-/merge_requests/13352.