From 2498da27456fe6558ac7224e9acaf9eab3e9fdf7 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 18 Dec 2018 06:17:01 -0700 Subject: [PATCH] Tesselation: Only set valid when successful Tesselation can fail for a number of reasons. When this happens, we set the triangulationValid flag to false to prevent using the broken triangulation. This will fall back to the slow OpenGL triangulation when DrawPolygon is called. --- common/geometry/shape_poly_set.cpp | 15 +++++++++------ include/geometry/polygon_triangulation.h | 3 --- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/common/geometry/shape_poly_set.cpp b/common/geometry/shape_poly_set.cpp index 99302e2f5e..a00a903d1a 100644 --- a/common/geometry/shape_poly_set.cpp +++ b/common/geometry/shape_poly_set.cpp @@ -1869,12 +1869,10 @@ void SHAPE_POLY_SET::CacheTriangulation() tmpSet.Fracture( PM_FAST ); m_triangulatedPolys.clear(); + m_triangulationValid = true; for( int i = 0; i < tmpSet.OutlineCount(); i++ ) { - if( tmpSet.Outline( i ).PointCount() < 3 ) // malformed polygon - continue; - m_triangulatedPolys.push_back( std::make_unique() ); PolygonTriangulation tess( *m_triangulatedPolys.back() ); @@ -1883,12 +1881,17 @@ void SHAPE_POLY_SET::CacheTriangulation() if( !tess.TesselatePolygon( tmpSet.Polygon( i ).front() ) ) { tmpSet.Fracture( PM_FAST ); - tess.TesselatePolygon( tmpSet.Polygon( i ).front() ); + + if( !tess.TesselatePolygon( tmpSet.Polygon( i ).front() ) ) + { + m_triangulatedPolys.pop_back(); + m_triangulationValid = false; + } } } - m_triangulationValid = true; - m_hash = checksum(); + if( m_triangulationValid ) + m_hash = checksum(); } diff --git a/include/geometry/polygon_triangulation.h b/include/geometry/polygon_triangulation.h index 8d9ad102df..335eee49da 100644 --- a/include/geometry/polygon_triangulation.h +++ b/include/geometry/polygon_triangulation.h @@ -651,9 +651,6 @@ public: { ClipperLib::Clipper c; - if( aPoly.PointCount() < 3 ) // Malformed polygon - return false; - m_bbox = aPoly.BBox(); m_result.Clear();