trimesh
trimesh copied to clipboard
Crash in extrude_polygon
Hello, We are experiencing a crash in extrude_polygon. Tested on 3.9.8 and 3.10.2, both have the crash. Here is a reproducing snippet:
import shapely.wkt
from trimesh.creation import extrude_polygon
for _ in range(1000):
p = shapely.wkt.loads('POLYGON ((-2.125361540432678 -3.5203325307059847, -2.125361540432678 -3.5203325307059843, -3.5643135530312637 -4.096454999083045, -5.25922868808552 0.1368489920640477, -3.8202766754869346 0.7129714604411084, -4.3852483871716865 2.1240727908234724, -0.2262128866505627 3.789252572810046, 0.3851766334439413 2.396735838803058, 1.8519793310883754 2.9840090650053437, 3.5227344908546447 -1.1889517752090746, 2.1079424507144195 -1.825417395651726, 2.6729141623991746 -3.236518726034097, -1.560389828747923 -4.931433861088356, -2.125361540432678 -3.5203325307059847), (-2.125361540432678 -3.5203325307059847, -2.0325259264428044 -3.4831633390881493, -2.05652174659513 -3.4232301901529745, -2.125361540432678 -3.5203325307059847))')
p2 = extrude_polygon(p, 3.3)
print(p)
print(p2)
We pretty consistently (~50%) get
Process finished with exit code -1073741819 (0xC0000005)
Which I believe is an access violation. Tested on windows and linux, installation via conda-forge.
This is the conda environment.yml that we use:
name: trimeshtest
channels:
- anaconda
- conda-forge
dependencies:
- anaconda::python = 3.7
- conda-forge::numpy = 1.21.5
- anaconda::shapely
- conda-forge::trimesh = 3.10.2
- pip:
- triangle
Thanks for the report! It's failing to triangulate the polygon, and I'm definitely reproducing the segfault in triangle.triangulate
which isn't ideal behavior. I noticed p2 = extrude_polygon(p, 3.3, engine='earcut')
also failed, which made me suspicious of the polygon (as earcut is a completely unrelated implementation of polygon triangulation):
In [15]: p.is_valid
Out[15]: True
In [16]: p.is_simple
Out[16]: True
In [17]: p.is_closed
Out[17]: False
Not sure what the correct thing to do here is... I suppose a less confusing error message if not polygon.is_closed
might help with debugging over an esoteric segfault.