From afc5d13172eee7a883552313b03d004b124812c0 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 26 May 2014 08:54:04 +0200 Subject: [PATCH] Apply a workaround in 3D_draw.cpp to avoid crash in boost::polygon (try to fix Bug #1322804) This workaround was already used (bzr 4301, in file plot_board_layers.cpp) also to avoid similar crashes (uses 18 segments instead of 16 to approximate a circle by segments). Minor code cleanup in dialog_plot. --- 3d-viewer/3d_draw.cpp | 9 ++++++++- pcbnew/dialogs/dialog_plot.cpp | 6 ++---- pcbnew/dialogs/dialog_plot.h | 3 +-- polygon/PolyLine.cpp | 4 ++-- polygon/PolyLine.h | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index 82abd0b0de..f653ad27da 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -240,7 +240,12 @@ void EDA_3D_CANVAS::BuildBoard3DView() bool realistic_mode = g_Parm_3D_Visu.IsRealisticMode(); // Number of segments to convert a circle to polygon - const int segcountforcircle = 16; + // Boost polygon (at least v 1.54, v1.55 and previous) in very rare cases crashes + // when using 16 segments to approximate a circle. + // So using 18 segments is a workaround to try to avoid these crashes + // ( We already used this trick in plot_board_layers.cpp, + // see PlotSolderMaskLayer() ) + const int segcountforcircle = 18; double correctionFactor = 1.0 / cos( M_PI / (segcountforcircle * 2) ); const int segcountLowQuality = 12; // segments to draw a circle with low quality // to reduce time calculations @@ -355,9 +360,11 @@ void EDA_3D_CANVAS::BuildBoard3DView() LAYER_NUM zonelayer = zone->GetLayer(); if( zonelayer == layer ) + { zone->TransformSolidAreasShapesToPolygonSet( hightQualityMode ? bufferPolys : bufferZonesPolys, segcountLowQuality, correctionFactorLQ ); + } } } diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index 6e66dff99f..230f170b65 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -46,8 +46,6 @@ DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aParent ) : m_plotOpts( aParent->GetPlotSettings() ) { m_config = Kiface().KifaceSettings(); - m_brdSettings = m_board->GetDesignSettings(); - Init_Dialog(); GetSizer()->Fit( this ); @@ -101,9 +99,9 @@ void DIALOG_PLOT::Init_Dialog() break; } - msg = StringFromValue( g_UserUnit, m_brdSettings.m_SolderMaskMargin, true ); + msg = StringFromValue( g_UserUnit, m_board->GetDesignSettings().m_SolderMaskMargin, true ); m_SolderMaskMarginCurrValue->SetLabel( msg ); - msg = StringFromValue( g_UserUnit, m_brdSettings.m_SolderMaskMinWidth, true ); + msg = StringFromValue( g_UserUnit, m_board->GetDesignSettings().m_SolderMaskMinWidth, true ); m_SolderMaskMinWidthCurrValue->SetLabel( msg ); // Set units and value for HPGL pen size (this param in in mils). diff --git a/pcbnew/dialogs/dialog_plot.h b/pcbnew/dialogs/dialog_plot.h index d198a9a023..b5cd562590 100644 --- a/pcbnew/dialogs/dialog_plot.h +++ b/pcbnew/dialogs/dialog_plot.h @@ -41,8 +41,7 @@ public: private: PCB_EDIT_FRAME* m_parent; BOARD* m_board; - BOARD_DESIGN_SETTINGS m_brdSettings; - wxConfigBase* m_config; + wxConfigBase* m_config; std::vector m_layerList; // List to hold CheckListBox layer numbers double m_XScaleAdjust; // X scale factor adjust to compensate // plotter X scaling error diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index 3ea299c330..c9ca85356d 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -1222,7 +1222,7 @@ int CPolyLine::HitTestForCorner( const wxPoint& aPos, int aDistMax ) const * Copy the contours to a KI_POLYGON_WITH_HOLES * The first contour is the main outline, others are holes */ -void CPOLYGONS_LIST::ExportTo( KI_POLYGON_WITH_HOLES& aPolygoneWithHole ) +void CPOLYGONS_LIST::ExportTo( KI_POLYGON_WITH_HOLES& aPolygoneWithHole ) const { unsigned corners_count = m_cornersList.size(); @@ -1273,7 +1273,7 @@ void CPOLYGONS_LIST::ExportTo( KI_POLYGON_WITH_HOLES& aPolygoneWithHole ) * Each contour is copied into a KI_POLYGON, and each KI_POLYGON * is append to aPolygons */ -void CPOLYGONS_LIST::ExportTo( KI_POLYGON_SET& aPolygons ) +void CPOLYGONS_LIST::ExportTo( KI_POLYGON_SET& aPolygons ) const { std::vector cornerslist; unsigned corners_count = GetCornersCount(); diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index 2610a5d765..23a747edab 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -164,7 +164,7 @@ public: * Copy all contours to a KI_POLYGON_SET * @param aPolygons = the KI_POLYGON_WITH_HOLES to populate */ - void ExportTo( KI_POLYGON_SET& aPolygons ); + void ExportTo( KI_POLYGON_SET& aPolygons ) const; /** * Function ExportTo @@ -172,7 +172,7 @@ public: * The first contour is the main outline, others are holes * @param aPolygoneWithHole = the KI_POLYGON_WITH_HOLES to populate */ - void ExportTo( KI_POLYGON_WITH_HOLES& aPolygoneWithHole ); + void ExportTo( KI_POLYGON_WITH_HOLES& aPolygoneWithHole ) const; /** * Function ImportFrom