I ran into what I think might be a bug/regression in
vtkFeatureEdges, where the filter tries and fails to allocate a very large array.
The following code:
from vtkmodules.vtkFiltersCore import vtkFeatureEdges from vtkmodules.vtkFiltersSources import vtkSphereSource N_CELLS = 2_000_000 source = vtkSphereSource() source.LatLongTessellationOn() source.SetEndPhi(90) source.SetThetaResolution(1000) source.SetPhiResolution(N_CELLS // 1000 + 1) source.Update() print("Cell count:", source.GetOutput().GetNumberOfCells()) feature_edges = vtkFeatureEdges() feature_edges.ExtractAllEdgeTypesOff() feature_edges.ColoringOff() feature_edges.BoundaryEdgesOn() feature_edges.SetInputConnection(source.GetOutputPort()) feature_edges.Update() print("Boundary edges:", feature_edges.GetOutput().GetNumberOfCells())
crashes (exit code -1073740791) on my system (Windows) with the following output:
Cell count: 2000000 2021-12-21 13:52:58.971 ( 0.334s) [ ]vtkGenericDataArray.txx:389 ERR| vtkTypeInt64Array (000002064F960CD0): Unable to allocate 20000000000 elements of size 8 bytes.
Now this might be a bug in VTK – I have created an issue for it – but my main question is: how can I handle this error in Python? I can observe error events (on the
vtkOutputWindow) but I don’t think I can do anything there to return to the calling Python code. Does anyone have any suggestions on how to handle such errors in a Python application?