From 53fe70950d8de972c52b91b82a1b103182c2f949 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 22 Aug 2012 11:46:36 -0300 Subject: [PATCH] poly2d/: try to work around spurious aborts in CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2 cameo encountered spurious aborts with the following message: terminate called after throwing an instance of 'CGAL::Precondition_exception what(): CGAL ERROR: precondition violation! Expr: is_simple_2(first, last, traits) File: /usr/include/CGAL/Polygon_2/Polygon_2_algorithms_impl.h Line: 420 These aborts come and go even if just the coordinate origin is slightly changed. Setting CGAL_POLYGON_NO_PRECONDITIONS in p2d_area_holes.cpp made them go away in some cases, but cameo could still run into an assertion violation (in CGAL). We now check all the polygons, outer boundary and holes, being sent to CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2 for simplicity, and stop recursing if there is any hint of a problem. This seems to avoid trouble for now, but the issue deserves further investigation. --- poly2d/p2d_area_holes.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/poly2d/p2d_area_holes.cpp b/poly2d/p2d_area_holes.cpp index 7118766..28bd9ef 100644 --- a/poly2d/p2d_area_holes.cpp +++ b/poly2d/p2d_area_holes.cpp @@ -23,6 +23,21 @@ extern "C" { #include "poly2d.h" } +/* + * @@@ Prevent spurious aborts with + * + * terminate called after throwing an instance of 'CGAL::Precondition_exception' + * what(): CGAL ERROR: precondition violation! + * Expr: is_simple_2(first, last, traits) + * File: /usr/include/CGAL/Polygon_2/Polygon_2_algorithms_impl.h + * Line: 420 + * + * Note that we also need to check the polygons for simplicity in recurse_area, + * or this may still lead to assertion failures. + */ + +#define CGAL_POLYGON_NO_PRECONDITIONS + #include "cgal_helper.h" #include @@ -55,6 +70,14 @@ static void append_poly(Polygon_2 poly, struct p2d ***last) static void recurse_area(Polygon_with_holes poly, double current, double next, struct p2d ***last) { + if (!poly.outer_boundary().is_simple()) + return; + for (Polygon_with_holes::Hole_const_iterator + hit = poly.holes_begin(); + hit != poly.holes_end(); ++hit) + if (!hit->is_simple()) + return; + PolygonPtrVector tmp = CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2( current, poly);