From a347aa764756c0a91d6182dba30b44f6179a559c Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Fri, 29 Sep 2023 19:51:57 -0400 Subject: [PATCH] StartPlot can fail and leave a broken file handle Related https://gitlab.com/kicad/code/kicad/-/issues/15782 --- common/plotters/GERBER_plotter.cpp | 2 +- pcbnew/plot_board_layers.cpp | 43 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/common/plotters/GERBER_plotter.cpp b/common/plotters/GERBER_plotter.cpp index e7ce54f66c..b481f3a9c3 100644 --- a/common/plotters/GERBER_plotter.cpp +++ b/common/plotters/GERBER_plotter.cpp @@ -251,7 +251,7 @@ bool GERBER_PLOTTER::StartPlot( const wxString& aPageNumber ) // Create a temp file in system temp to avoid potential network share buffer issues for // the final read and save. m_workFilename = wxFileName::CreateTempFileName( "" ); - workFile = wxFopen( m_workFilename, wxT( "wt" )); + workFile = wxFopen( m_workFilename, wxT( "wt" ) ); m_outputFile = workFile; wxASSERT( m_outputFile ); diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 4b61b31c99..c8a70a425e 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -1227,30 +1227,31 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aL AddGerberX2Attribute( plotter, aBoard, aLayer, not useX2mode ); } - plotter->StartPlot( wxT( "1" ) ); - - // Plot the frame reference if requested - if( aPlotOpts->GetPlotFrameRef() ) + if( plotter->StartPlot( wxT( "1" ) ) ) { - PlotDrawingSheet( plotter, aBoard->GetProject(), aBoard->GetTitleBlock(), - aBoard->GetPageSettings(), &aBoard->GetProperties(), wxT( "1" ), 1, - aSheetName, aSheetPath, aBoard->GetFileName(), - renderSettings->GetLayerColor( LAYER_DRAWINGSHEET ) ); + // Plot the frame reference if requested + if( aPlotOpts->GetPlotFrameRef() ) + { + PlotDrawingSheet( plotter, aBoard->GetProject(), aBoard->GetTitleBlock(), + aBoard->GetPageSettings(), &aBoard->GetProperties(), wxT( "1" ), + 1, aSheetName, aSheetPath, aBoard->GetFileName(), + renderSettings->GetLayerColor( LAYER_DRAWINGSHEET ) ); - if( aPlotOpts->GetMirror() ) - initializePlotter( plotter, aBoard, aPlotOpts ); + if( aPlotOpts->GetMirror() ) + initializePlotter( plotter, aBoard, aPlotOpts ); + } + + // When plotting a negative board: draw a black rectangle (background for plot board + // in white) and switch the current color to WHITE; note the color inversion is actually + // done in the driver (if supported) + if( aPlotOpts->GetNegative() ) + { + BOX2I bbox = aBoard->ComputeBoundingBox(); + FillNegativeKnockout( plotter, bbox ); + } + + return plotter; } - - // When plotting a negative board: draw a black rectangle (background for plot board - // in white) and switch the current color to WHITE; note the color inversion is actually - // done in the driver (if supported) - if( aPlotOpts->GetNegative() ) - { - BOX2I bbox = aBoard->ComputeBoundingBox(); - FillNegativeKnockout( plotter, bbox ); - } - - return plotter; } delete plotter->RenderSettings();