Skip to content

Commit

Permalink
fix: process bad triangles
Browse files Browse the repository at this point in the history
Fixes extremely rare case when search for first half-edge of the polygon during processing bad triangles may stuck in an infinite loop.
  • Loading branch information
andywiecko committed Nov 6, 2023
1 parent 370b4a0 commit 54d6034
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,24 +1941,30 @@ private void VisitEdge(float2 p, int t0, int t1)
private void ProcessBadTriangles(int pId, NativeList<int> heQueue, NativeList<int> tQueue)
{
// 1. Find the "first" halfedge of the polygon.
var id = 3 * badTriangles[0];
var initHe = -1;
while (true)
for (int i = 0; i < badTriangles.Length; i++)
{
id = NextHalfedge(id);
var he = halfedges[id];
if (he == -1 || !badTriangles.Contains(he / 3))
var tId = badTriangles[i];
for (int t = 0; t < 3; t++)
{
var he = 3 * tId + t;
var ohe = halfedges[he];
if (ohe == -1 || !badTriangles.Contains(ohe / 3))
{
pathPoints.Add(triangles[he]);
pathHalfedges.Add(ohe);
initHe = he;
break;
}
}
if (initHe != -1)
{
initHe = id;
pathPoints.Add(triangles[id]);
pathHalfedges.Add(he);
break;
}
id = he;
}

// 2. Build polygon path from halfedges and points.
id = initHe;
var id = initHe;
var initPoint = pathPoints[0];
while (true)
{
Expand Down

0 comments on commit 54d6034

Please sign in to comment.