From bea2d42e8cd5a30f775146b604d170f93e9d2a1e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 15 Dec 2019 14:02:12 +0100 Subject: [PATCH] Gerbview,export to pcbnew: avoid exporting not valid polygons. Gerber regions are exported as polygons (they are filled polygon). The fix ensure the polygons are simple and valid. Invalid polygons crash Pcbnew. From master branch, commit 25504319. --- gerbview/export_to_pcbnew.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index 59ebce744f..a71b9a6516 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -536,11 +536,21 @@ void GBR_TO_PCB_EXPORTER::writePcbLineItem( bool aIsArc, wxPoint& aStart, wxPoin void GBR_TO_PCB_EXPORTER::writePcbPolygonItem( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer ) { - fprintf( m_fp, "(gr_poly (pts " ); - SHAPE_POLY_SET polys = aGbrItem->m_Polygon; + + // Cleanup the polygon + polys.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); + + // Ensure the polygon is valid: + if( polys.OutlineCount() == 0 ) + return; + + polys.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); + SHAPE_LINE_CHAIN& poly = polys.Outline( 0 ); + fprintf( m_fp, "(gr_poly (pts " ); + #define MAX_COORD_CNT 4 int jj = MAX_COORD_CNT; int cnt_max = poly.PointCount() -1;