Skip to content

Fix CreateFromPolyData() for non-64-bit cell storage - #53

Merged
valette merged 1 commit into
valette:masterfrom
MITK:fix-create-from-polydata-cell-storage
Sep 16, 2026
Merged

valette merged 1 commit into
valette:masterfrom
MITK:fix-create-from-polydata-cell-storage

Conversation

@kislinsk

Copy link
Copy Markdown
Contributor

Fix crash in vtkSurfaceBase::CreateFromPolyData() for non-64-bit cell storage

GetFaceVertices() returns raw vtkIdType* pointers into the polygon connectivity, so it relies on the vtkCellArray using 64-bit AOS storage: it fetches the arrays with GetOffsetsAOSArray64() / GetConnectivityAOSArray64() (or GetOffsetsArray64() on older VTK), which are FastDownCasts that return null for any other layout. Init() guarantees 64-bit storage for meshes built from scratch, but CreateFromPolyData() shallow-copies the input and inherits whatever layout it carries.

Since VTK 9.4 cell arrays can hold 32-bit or fixed-size (implicit offsets) storage, and filters use them: vtkSurfaceNets3D, for example, emits fixed-size 32-bit cells by default at least since VTK 9.7. Passing such a polydata to CreateFromPolyData() dereferences null in GetFaceVertices() and crashes with an access violation.

Fix: when the input's polygons are not in 64-bit storage, copy them into a 64-bit vtkCellArray after the shallow copy, leaving the caller's array untouched.

Reproduce (VTK 9.7): vtkSphereSource → polys->ConvertToFixedSize32BitStorage() (or any vtkSurfaceNets3D output) → vtkSurface::CreateFromPolyData(). Crashes before, works after; 64-bit inputs behave as before.

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 <noreply@anthropic.com>
@valette
valette merged commit 82a9e25 into valette:master Sep 16, 2026
6 checks passed
@valette

valette commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants