From 74623847b72f77b9509ee88cfa9164981787dd48 Mon Sep 17 00:00:00 2001 From: Megidd Git Date: Sat, 11 Sep 2021 11:50:24 +0430 Subject: [PATCH] Mesh: fix infinite loop when repairing mesh facet indices --- src/Mod/Mesh/App/Core/Degeneration.cpp | 9 ++++++--- src/Mod/Mesh/App/Core/TopoAlgorithm.cpp | 8 +++++--- src/Mod/Mesh/App/Core/TopoAlgorithm.h | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Mod/Mesh/App/Core/Degeneration.cpp b/src/Mod/Mesh/App/Core/Degeneration.cpp index 440fb0bdeb..261c30c452 100644 --- a/src/Mod/Mesh/App/Core/Degeneration.cpp +++ b/src/Mod/Mesh/App/Core/Degeneration.cpp @@ -1249,9 +1249,12 @@ bool MeshFixCorruptedFacets::Fixup() if ( it->Area() <= FLOAT_EPS ) { unsigned long uId = it.Position(); - cTopAlg.RemoveCorruptedFacet(uId); - // due to a modification of the array the iterator became invalid - it.Set(uId-1); + bool removed = cTopAlg.RemoveCorruptedFacet(uId); + if (removed) { + // due to a modification of the array the iterator became invalid + it.Set(uId-1); + } + } } diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp index 49176331dd..76f13a68f1 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp @@ -1474,9 +1474,9 @@ void MeshTopoAlgorithm::RemoveDegeneratedFacet(unsigned long index) } } -void MeshTopoAlgorithm::RemoveCorruptedFacet(unsigned long index) +bool MeshTopoAlgorithm::RemoveCorruptedFacet(unsigned long index) { - if (index >= _rclMesh._aclFacetArray.size()) return; + if (index >= _rclMesh._aclFacetArray.size()) return false; MeshFacet& rFace = _rclMesh._aclFacetArray[index]; // coincident corners (topological) @@ -1494,9 +1494,11 @@ void MeshTopoAlgorithm::RemoveCorruptedFacet(unsigned long index) rFace._aulNeighbours[1] = ULONG_MAX; rFace._aulNeighbours[2] = ULONG_MAX; _rclMesh.DeleteFacet(index); - return; + return true; } } + + return false; } void MeshTopoAlgorithm::FillupHoles(unsigned long length, int level, diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.h b/src/Mod/Mesh/App/Core/TopoAlgorithm.h index 06056c22fc..199ca6a4bd 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.h +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.h @@ -240,7 +240,7 @@ public: * Removes the corrupted facet at position \a index from the mesh structure. * A facet is corrupted if the indices of its corner points are not all different. */ - void RemoveCorruptedFacet(unsigned long index); + bool RemoveCorruptedFacet(unsigned long index); /** * Closes holes in the mesh that consists of up to \a length edges. In case a fit * needs to be done then the points of the neighbours of \a level rings will be used.