From 66ec0f59e73ce97c0178a2f7f29d5534c1ed9e6c Mon Sep 17 00:00:00 2001 From: Bohumir Zamecnik Date: Thu, 26 May 2011 22:02:15 +0200 Subject: [PATCH] Fix DTSweep.FinalizationConvexHull(), DTSweep.FinalizationPolygon(). --- Triangulation/Delaunay/Sweep/DTSweep.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Triangulation/Delaunay/Sweep/DTSweep.cs b/Triangulation/Delaunay/Sweep/DTSweep.cs index a69ec88..eff5d07 100644 --- a/Triangulation/Delaunay/Sweep/DTSweep.cs +++ b/Triangulation/Delaunay/Sweep/DTSweep.cs @@ -157,6 +157,12 @@ private static void FinalizationConvexHull( DTSweepContext tcx ) { t1 = t1.NeighborCWFrom(tcx.Front.Head.Point); do { tcx.RemoveFromList(t1); + // NOTE: there was a NullReferenceException + // probably t1 was null + if (t1 == null) + { + break; // TODO: is this solution OK? + } p1 = t1.PointCCWFrom(p1); t1 = t1.NeighborCCWFrom(p1); } while (p1 != first); @@ -195,7 +201,21 @@ private static void FinalizationPolygon( DTSweepContext tcx ) { // Get an Internal triangle to start with DelaunayTriangle t = tcx.Front.Head.Next.Triangle; TriangulationPoint p = tcx.Front.Head.Next.Point; - while (!t.GetConstrainedEdgeCW(p)) t = t.NeighborCCWFrom(p); + while (!t.GetConstrainedEdgeCW(p)) + { + DelaunayTriangle nextTriangle = t.NeighborCCWFrom(p); + // NOTE: there was a NullReferenceException + // probably t was null + // TODO: is this solution ok? + if (nextTriangle != null) + { + t = nextTriangle; + } + else + { + break; + } + } // Collect interior triangles constrained by edges tcx.MeshClean(t);