From cf9f19818ca5886275019f8e93c7fb8ec0e4bde6 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Tue, 26 Nov 2013 20:04:57 -0600 Subject: prevent crash in CGAL nef3. fix #issue 410 . also deal w qmake bug re .h files diff --git a/openscad.pro b/openscad.pro index fd9f494..b38419e 100644 --- a/openscad.pro +++ b/openscad.pro @@ -39,6 +39,7 @@ debug: DEFINES += DEBUG TEMPLATE = app INCLUDEPATH += src +DEPENDPATH += src # Handle custom library location. # Used when manually installing 3rd party libraries @@ -368,6 +369,7 @@ HEADERS += src/cgal.h \ src/PolySetCGALEvaluator.h \ src/CGALRenderer.h \ src/CGAL_Nef_polyhedron.h \ + src/CGAL_Nef3_workaround.h \ src/cgalworker.h SOURCES += src/cgalutils.cc \ diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index ec01315..242fe0f 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -159,9 +159,19 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node) PRINT("Hull() currently requires a valid 2-manifold. Please modify your design. See http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/STL_Import_and_Export"); } else { - chN.p3->convert_to_Polyhedron(P); - std::transform(P.vertices_begin(), P.vertices_end(), std::back_inserter(points3d), - boost::bind(static_cast(&CGAL_Polyhedron::Vertex::point), _1)); + bool err = false; + try{ + err = nefworkaround::convert_to_Polyhedron( *(chN.p3), P ); + //chN.p3->convert_to_Polyhedron(P); + } catch (...) { + err = true; + } + if (err) { + PRINT("ERROR: CGAL NefPolyhedron->Polyhedron conversion failed"); + } else { + std::transform(P.vertices_begin(), P.vertices_end(), std::back_inserter(points3d), + boost::bind(static_cast(&CGAL_Polyhedron::Vertex::point), _1)); + } } } chnode->progress_report(); diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 440f4ed..4761d26 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -98,11 +98,22 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset() CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { CGAL_Polyhedron P; - this->p3->convert_to_Polyhedron(P); - ps = createPolySetFromPolyhedron(P); + bool err = nefworkaround::convert_to_Polyhedron( *(this->p3), P ); + //this->p3->convert_to_Polyhedron(P); + if (err) { + PRINT("ERROR: CGAL NefPolyhedron->Polyhedron conversion failed"); + } else { + ps = createPolySetFromPolyhedron(P); + } } catch (const CGAL::Precondition_exception &e) { - PRINTB("CGAL error in CGAL_Nef_polyhedron::convertToPolyset(): %s", e.what()); + PRINTB("CGAL Precondition error in CGAL_Nef_polyhedron::convertToPolyset(): %s", e.what()); + } + catch (const CGAL::Assertion_exception &e) { + PRINTB("CGAL Assertion error in CGAL_Nef_polyhedron::convertToPolyset(): %s", e.what()); + } + catch (...) { + PRINT("CGAL unknown error in CGAL_Nef_polyhedron::convertToPolyset()"); } CGAL::set_error_behaviour(old_behaviour); } diff --git a/src/cgal.h b/src/cgal.h index 45228be..69c8c27 100644 --- a/src/cgal.h +++ b/src/cgal.h @@ -27,6 +27,7 @@ using boost::uintmax_t; #include #include #include +#include #include #include #include @@ -48,9 +49,10 @@ typedef CGAL::Exact_predicates_exact_constructions_kernel CGAL_ExactKernel2; typedef CGAL::Polygon_2 CGAL_Poly2; typedef CGAL::Polygon_with_holes_2 CGAL_Poly2h; - //typedef CGAL::Cartesian CGAL_Kernel3; -typedef CGAL::Exact_predicates_exact_constructions_kernel CGAL_Kernel3; -typedef CGAL::Exact_predicates_exact_constructions_kernel::FT NT3; +typedef CGAL::Gmpq NT3; +typedef CGAL::Cartesian CGAL_Kernel3; +//typedef CGAL::Exact_predicates_exact_constructions_kernel::FT NT3; +//typedef CGAL::Exact_predicates_exact_constructions_kernel CGAL_Kernel3; typedef CGAL::Nef_polyhedron_3 CGAL_Nef_polyhedron3; typedef CGAL_Nef_polyhedron3::Aff_transformation_3 CGAL_Aff_transformation; diff --git a/src/export.cc b/src/export.cc index ec6e576..cef323e 100644 --- a/src/export.cc +++ b/src/export.cc @@ -42,7 +42,12 @@ void export_stl(CGAL_Nef_polyhedron *root_N, std::ostream &output) CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { CGAL_Polyhedron P; - root_N->p3->convert_to_Polyhedron(P); + //root_N->p3->convert_to_Polyhedron(P); + bool err = nefworkaround::convert_to_Polyhedron( *(root_N->p3), P ); + if (err) { + PRINT("ERROR: CGAL NefPolyhedron->Polyhedron conversion failed"); + return; + } typedef CGAL_Polyhedron::Vertex Vertex; typedef CGAL_Polyhedron::Vertex_const_iterator VCI; @@ -114,6 +119,9 @@ void export_stl(CGAL_Nef_polyhedron *root_N, std::ostream &output) catch (const CGAL::Assertion_exception &e) { PRINTB("CGAL error in CGAL_Nef_polyhedron3::convert_to_Polyhedron(): %s", e.what()); } + catch (...) { + PRINT("CGAL unknown error in CGAL_Nef_polyhedron3::convert_to_Polyhedron()"); + } CGAL::set_error_behaviour(old_behaviour); } -- cgit v0.10.1