From d98494db5e0b79fd2c7beeaac5144b8c45a8e046 Mon Sep 17 00:00:00 2001 From: Stefan Dinkelacker Date: Tue, 15 Sep 2026 12:12:27 +0200 Subject: [PATCH] Fix CreateFromPolyData() for non-64-bit cell storage GetFaceVertices() returns raw pointers into the polygon connectivity and therefore relies on the vtkCellArray using 64-bit AOS storage. CreateFromPolyData() shallow-copies the input, so it inherits whatever layout the input carries. Since VTK 9.4 that can be 32-bit or fixed-size storage (vtkSurfaceNets3D emits fixed-size 32-bit cells by default), and the AOS64 downcast in GetFaceVertices() then returns null and crashes. Copy the polygons into 64-bit storage when needed. Init() already enforces 64-bit storage for meshes built from scratch. Co-Authored-By: Claude Fable 5.1 --- Common/vtkSurfaceBase.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Common/vtkSurfaceBase.cxx b/Common/vtkSurfaceBase.cxx index f226789..4895aa8 100644 --- a/Common/vtkSurfaceBase.cxx +++ b/Common/vtkSurfaceBase.cxx @@ -1413,6 +1413,21 @@ void vtkSurfaceBase::CreateFromPolyData(vtkPolyData *input) // just copy the polydata in input this->ShallowCopy(input); + #if ( (VTK_MAJOR_VERSION >= 9)) + // GetFaceVertices() hands out raw pointers into the polygon connectivity and + // therefore requires 64-bit AOS cell storage. The input may carry another + // layout (32-bit or fixed-size, e.g. from vtkSurfaceNets3D), so copy its + // polygons into 64-bit storage instead of converting the shared array in place. + if (!this->GetPolys()->IsStorage64Bit()) + { + vtkCellArray *Polys64 = vtkCellArray::New(); + Polys64->DeepCopy(this->GetPolys()); + Polys64->ConvertTo64BitStorage(); + this->SetPolys(Polys64); + Polys64->Delete(); + } + #endif + // Delete the cells that are not polygons vtkCellArray *VerticesCells=this->GetVerts(); vtkCellArray *LinesCells=this->GetLines();