diff options
-rw-r--r-- | src/polyset.cc | 12 | ||||
-rw-r--r-- | testdata/polygon-illegal-winding.scad | 15 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/polyset.cc b/src/polyset.cc index 8eccf37..b8e77f4 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -26,6 +26,8 @@ #include "polyset.h" #include "printutils.h" #include "Preferences.h" +#include <CGAL/assertions_behaviour.h> +#include <CGAL/exceptions.h> #include <Eigen/Core> #include <Eigen/LU> @@ -647,8 +649,10 @@ CGAL_Nef_polyhedron PolySet::render_cgal_nef_polyhedron() const #endif } - else + else // not (this->is2d) { + CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); + try { CGAL_Polyhedron P; CGAL_Build_PolySet builder(this); P.delegate(builder); @@ -657,6 +661,12 @@ CGAL_Nef_polyhedron PolySet::render_cgal_nef_polyhedron() const #endif CGAL_Nef_polyhedron3 N(P); return CGAL_Nef_polyhedron(N); + } + catch (CGAL::Assertion_exception e) { + PRINTF("ERROR: Illegal polygonal object - make sure all polygons are defined with the same winding order. Skipping affected object."); + CGAL::set_error_behaviour(old_behaviour); + return CGAL_Nef_polyhedron(); + } } return CGAL_Nef_polyhedron(); } diff --git a/testdata/polygon-illegal-winding.scad b/testdata/polygon-illegal-winding.scad new file mode 100644 index 0000000..612154a --- /dev/null +++ b/testdata/polygon-illegal-winding.scad @@ -0,0 +1,15 @@ +polyhedron + (points = [ + [0, -10, 60], [0, 10, 60], [0, 10, 0], [0, -10, 0], [60, -10, +60], [60, 10, 60], + [10, -10, 50], [10, 10, 50], [10, 10, 30], [10, -10, 30], [30, +-10, 50], [30, 10, 50] + ], + triangles = [ + [0,2,3], [0,1,2], [0,4,5], [0,5,1], [5,4,2], [2,4,3], + [6,8,9], [6,7,8], [6,10,11], [6,11,7], [10,8,11], + [10,9,8], [0,3,9], [9,0,6], [10,6, 0], [0,4,10], + [3,9,10], [3,10,4], [1,7,11], [1,11,5], [1,7,8], + [1,8,2], [2,8,11], [2,11,5] + ] + ); |