diff --git a/deps_src/clipper2/Clipper2Lib/src/clipper.engine.cpp b/deps_src/clipper2/Clipper2Lib/src/clipper.engine.cpp index a3a5c7ca1b..db1166d311 100644 --- a/deps_src/clipper2/Clipper2Lib/src/clipper.engine.cpp +++ b/deps_src/clipper2/Clipper2Lib/src/clipper.engine.cpp @@ -2978,8 +2978,14 @@ namespace Clipper2Lib { for (size_t idx = 0; idx < splits->size(); ++idx) { OutRec* split = (*splits)[idx]; - if (!split->pts && split->splits && - CheckSplitOwner(outrec, split->splits)) return true; //#942 + if (!split->pts && split->splits) + { + if (split->recursive_split == outrec) continue; + split->recursive_split = outrec; // emptied OutRecs can reference each other + + if (CheckSplitOwner(outrec, split->splits)) return true; //#942 + } + split = GetRealOutRec(split); if (!split || split == outrec || split->recursive_split == outrec) continue; split->recursive_split = outrec; // prevent infinite loops diff --git a/tests/libslic3r/test_clipper_utils.cpp b/tests/libslic3r/test_clipper_utils.cpp index ce1b3b76fa..44f74969e5 100644 --- a/tests/libslic3r/test_clipper_utils.cpp +++ b/tests/libslic3r/test_clipper_utils.cpp @@ -877,3 +877,11 @@ TEST_CASE("Uniting a few polygons in groups is one union", "[ClipperUtils]") { CHECK(union_overlapping_ex(polygons) == union_ex(polygons)); CHECK(union_overlapping_ex({}).empty()); } + +TEST_CASE("An even-odd union of a path retracing its edges covers the same area as the flat union", "[ClipperUtils]") { + // Building the PolyTree of this path leaves emptied output loops that point at each other, and looking for a + // loop's owner through them recursed until the stack overflowed. + const Polygons subject{ Polygon({ { 3, 0 }, { 3, 5 }, { 0, 3 }, { 5, 3 }, { 0, 5 }, { 5, 3 }, { 0, 3 }, + { 0, 0 }, { 0, 3 }, { 5, 3 }, { 0, 0 }, { 3, 3 }, { 2, 3 } }) }; + CHECK_THAT(area(union_ex(subject, pftEvenOdd)), Catch::Matchers::WithinRel(area(union_(subject, pftEvenOdd)), 1e-9)); +}