Skip to content

Commit ad5e85b

Browse files
committed
Prevent crash when earcut return no inidces
1 parent 1bb5a34 commit ad5e85b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Source/SpatialGeometryTools/Private/PolygonHelper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ TArray<int32> PolygonHelper::TessellatePolygon(const TArray<FVector> &Vertices,
170170
// tessellate using earcut
171171
const std::vector<N> Indices = mapbox::earcut<N>(Polygon);
172172

173+
// prevent crashes when earcut returns an empty array
173174
TArray<int32> Ret;
175+
if(Indices.size() <= 0)
176+
{
177+
return Ret;
178+
}
179+
174180
for(int i = 0; i < Indices.size() - 2; i += 3) {
175181
//if(!PolygonHelper::IsClockwise({Vertices[Indices[i]], Vertices[Indices[i+1]], Vertices[Indices[i+2]]}))
176182
if(bClockwise)

0 commit comments

Comments
 (0)