From b5eee9dd7ebcbc281646d3cb9c44b68b2001a9f8 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 16 Oct 2023 17:04:01 -0400 Subject: [PATCH] Coverity warning fixes. --- 3d-viewer/3d_canvas/board_adapter.cpp | 21 +++++++-- eeschema/eeschema_jobs_handler.cpp | 4 +- eeschema/sch_view.cpp | 9 ++-- eeschema/sim/simulator_frame_ui.cpp | 3 ++ eeschema/symbol_editor/symbol_edit_frame.cpp | 27 +++++++++--- pcbnew/dialogs/dialog_board_reannotate.cpp | 44 ++++++++++++------- .../dialog_cleanup_tracks_and_vias.cpp | 28 ++++++++---- pcbnew/dialogs/dialog_drc.cpp | 25 ++++++++--- pcbnew/dialogs/dialog_export_idf.cpp | 26 ++++++++--- pcbnew/dialogs/dialog_export_step.cpp | 36 ++++++++++----- pcbnew/dialogs/dialog_export_svg.cpp | 42 ++++++++++++------ pcbnew/dialogs/dialog_export_vrml.cpp | 36 ++++++++++----- .../dialogs/dialog_footprint_properties.cpp | 15 ++++++- .../dialog_footprint_properties_fp_editor.cpp | 15 ++++++- .../dialogs/dialog_footprint_wizard_list.cpp | 16 +++++-- pcbnew/dialogs/dialog_import_netlist.cpp | 24 +++++++--- pcbnew/dialogs/dialog_update_pcb.cpp | 22 +++++++--- pcbnew/import_gfx/dialog_import_gfx_pcb.cpp | 29 ++++++++---- pcbnew/router/pns_item.cpp | 1 + pcbnew/router/pns_joint.h | 6 ++- pcbnew/router/pns_router.cpp | 8 ++-- pcbnew/router/pns_walkaround.cpp | 9 +++- pcbnew/tools/drawing_tool.cpp | 8 +++- pcbnew/tools/pcb_selection_tool.cpp | 11 ++++- pcbnew/widgets/panel_footprint_chooser.cpp | 12 ++++- 25 files changed, 352 insertions(+), 125 deletions(-) diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index 8f17670469..843eff51c1 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2015-2022 Mario Luzeiro + * Copyright (C) 2015-2023 Mario Luzeiro * Copyright (C) 2023 CERN * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * @@ -223,10 +223,23 @@ BOARD_ADAPTER::~BOARD_ADAPTER() void BOARD_ADAPTER::ReloadColorSettings() noexcept { - wxASSERT( PgmOrNull() ); + wxCHECK( PgmOrNull(), /* void */ ); - PCBNEW_SETTINGS* settings = Pgm().GetSettingsManager().GetAppSettings(); - m_colors = Pgm().GetSettingsManager().GetColorSettings( settings->m_ColorTheme ); + PCBNEW_SETTINGS* cfg = nullptr; + + try + { + cfg = Pgm().GetSettingsManager().GetAppSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + m_colors = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme ); + } } diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index 71a4dac214..582b5bed7f 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -934,8 +934,8 @@ int EESCHEMA_JOBS_HANDLER::JobSchErc( JOB* aJob ) m_reporter->Report( _( "Running ERC...\n" ), RPT_SEVERITY_INFO ); - DS_PROXY_VIEW_ITEM* drawingSheet = getDrawingSheetProxyView( sch ); - ercTester.RunTests( drawingSheet, nullptr, m_progressReporter ); + std::unique_ptr drawingSheet( getDrawingSheetProxyView( sch ) ); + ercTester.RunTests( drawingSheet.get(), nullptr, m_progressReporter ); markersProvider->SetSeverities( ercJob->m_severity ); diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index 00d8c7e3ec..35b1479aca 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -160,11 +160,10 @@ void SCH_VIEW::DisplaySymbol( LIB_SYMBOL* aSymbol ) // Draw the parent items if the symbol is inherited from another symbol. if( aSymbol->IsAlias() ) { - std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol().lock(); - - wxCHECK( parent, /* void */ ); - - drawnSymbol = parent.get(); + if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol().lock() ) + drawnSymbol = parent.get(); + else + wxCHECK( false, /* void */ ); } for( LIB_ITEM& item : drawnSymbol->GetDrawItems() ) diff --git a/eeschema/sim/simulator_frame_ui.cpp b/eeschema/sim/simulator_frame_ui.cpp index 40a538d262..cc6b923169 100644 --- a/eeschema/sim/simulator_frame_ui.cpp +++ b/eeschema/sim/simulator_frame_ui.cpp @@ -2059,6 +2059,9 @@ bool SIMULATOR_FRAME_UI::loadJsonWorkbook( const wxString& aPath ) m_simulatorFrame->LoadSimulator( simTab->GetSimCommand(), simTab->GetSimOptions() ); simTab = dynamic_cast( m_plotNotebook->GetPage( 0 ) ); + + wxCHECK( simTab, false ); + simTab->SetLastSchTextSimCommand( js[ "last_sch_text_sim_command" ] ); } } diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index d7b243f2fa..538e525602 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -277,8 +277,21 @@ SYMBOL_EDIT_FRAME::~SYMBOL_EDIT_FRAME() // current screen is destroyed in EDA_DRAW_FRAME SetScreen( m_dummyScreen ); - auto libedit = Pgm().GetSettingsManager().GetAppSettings(); - Pgm().GetSettingsManager().Save( libedit ); + SYMBOL_EDITOR_SETTINGS* cfg = nullptr; + + try + { + cfg = Pgm().GetSettingsManager().GetAppSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + Pgm().GetSettingsManager().Save( cfg ); + } delete m_libMgr; } @@ -745,6 +758,8 @@ wxString SYMBOL_EDIT_FRAME::SetCurLib( const wxString& aLibNickname ) void SYMBOL_EDIT_FRAME::SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom ) { + wxCHECK( m_toolManager, /* void */ ); + m_toolManager->RunAction( EE_ACTIONS::clearSelection ); GetCanvas()->GetView()->Clear(); delete m_symbol; @@ -811,12 +826,14 @@ void SYMBOL_EDIT_FRAME::SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom ) } else if( IsSymbolAlias() ) { - std::shared_ptr rootSymbol = m_symbol->GetRootSymbol().lock(); + wxString rootSymbolName; // Don't assume the parent symbol shared pointer is still valid. - wxCHECK( rootSymbol, /* void */ ); + if( std::shared_ptr rootSymbol = m_symbol->GetRootSymbol().lock() ) + rootSymbolName = rootSymbol->GetName(); + else + wxCHECK( false, /* void */ ); - wxString rootSymbolName = rootSymbol->GetName(); int unit = GetUnit(); int convert = GetConvert(); wxString msg; diff --git a/pcbnew/dialogs/dialog_board_reannotate.cpp b/pcbnew/dialogs/dialog_board_reannotate.cpp index 6b0ea90d98..a983f92fd9 100644 --- a/pcbnew/dialogs/dialog_board_reannotate.cpp +++ b/pcbnew/dialogs/dialog_board_reannotate.cpp @@ -170,23 +170,37 @@ DIALOG_BOARD_REANNOTATE::DIALOG_BOARD_REANNOTATE( PCB_EDIT_FRAME* aParentFrame ) DIALOG_BOARD_REANNOTATE::~DIALOG_BOARD_REANNOTATE() { GetParameters(); // Get the current menu settings - PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings(); - cfg->m_Reannotate.sort_on_fp_location = m_locationChoice->GetSelection() == 0; - cfg->m_Reannotate.remove_front_prefix = m_RemoveFrontPrefix->GetValue(); - cfg->m_Reannotate.remove_back_prefix = m_RemoveBackPrefix->GetValue(); - cfg->m_Reannotate.exclude_locked = m_ExcludeLocked->GetValue(); - cfg->m_Reannotate.grid_index = m_gridIndex; - cfg->m_Reannotate.sort_code = m_sortCode; - cfg->m_Reannotate.annotation_choice = m_annotationScope; - cfg->m_Reannotate.report_severity = m_severity; + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_Reannotate.front_refdes_start = m_FrontRefDesStart->GetValue(); - cfg->m_Reannotate.back_refdes_start = m_BackRefDesStart->GetValue(); - cfg->m_Reannotate.front_prefix = m_FrontPrefix->GetValue(); - cfg->m_Reannotate.back_prefix = m_BackPrefix->GetValue(); - cfg->m_Reannotate.exclude_list = m_ExcludeList->GetValue(); - cfg->m_Reannotate.report_file_name = m_MessageWindow->GetFileName(); + try + { + cfg = m_frame->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + cfg->m_Reannotate.sort_on_fp_location = m_locationChoice->GetSelection() == 0; + cfg->m_Reannotate.remove_front_prefix = m_RemoveFrontPrefix->GetValue(); + cfg->m_Reannotate.remove_back_prefix = m_RemoveBackPrefix->GetValue(); + cfg->m_Reannotate.exclude_locked = m_ExcludeLocked->GetValue(); + + cfg->m_Reannotate.grid_index = m_gridIndex; + cfg->m_Reannotate.sort_code = m_sortCode; + cfg->m_Reannotate.annotation_choice = m_annotationScope; + cfg->m_Reannotate.report_severity = m_severity; + + cfg->m_Reannotate.front_refdes_start = m_FrontRefDesStart->GetValue(); + cfg->m_Reannotate.back_refdes_start = m_BackRefDesStart->GetValue(); + cfg->m_Reannotate.front_prefix = m_FrontPrefix->GetValue(); + cfg->m_Reannotate.back_prefix = m_BackPrefix->GetValue(); + cfg->m_Reannotate.exclude_list = m_ExcludeList->GetValue(); + cfg->m_Reannotate.report_file_name = m_MessageWindow->GetFileName(); + } } diff --git a/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp b/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp index f4c2e5c704..4faf1df87f 100644 --- a/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp +++ b/pcbnew/dialogs/dialog_cleanup_tracks_and_vias.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -59,14 +59,26 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS::DIALOG_CLEANUP_TRACKS_AND_VIAS( PCB_EDIT_FRAME* DIALOG_CLEANUP_TRACKS_AND_VIAS::~DIALOG_CLEANUP_TRACKS_AND_VIAS() { - auto cfg = m_parentFrame->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue(); - cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue(); - cfg->m_Cleanup.cleanup_unconnected = m_deleteUnconnectedOpt->GetValue(); - cfg->m_Cleanup.cleanup_short_circuits = m_cleanShortCircuitOpt->GetValue(); - cfg->m_Cleanup.cleanup_tracks_in_pad = m_deleteTracksInPadsOpt->GetValue(); - cfg->m_Cleanup.delete_dangling_vias = m_deleteDanglingViasOpt->GetValue(); + try + { + cfg = m_parentFrame->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue(); + cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue(); + cfg->m_Cleanup.cleanup_unconnected = m_deleteUnconnectedOpt->GetValue(); + cfg->m_Cleanup.cleanup_short_circuits = m_cleanShortCircuitOpt->GetValue(); + cfg->m_Cleanup.cleanup_tracks_in_pad = m_deleteTracksInPadsOpt->GetValue(); + cfg->m_Cleanup.delete_dangling_vias = m_deleteDanglingViasOpt->GetValue(); + } m_changesTreeModel->DecRef(); } diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index a3e8e32e63..0d734886a5 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -160,14 +160,27 @@ DIALOG_DRC::~DIALOG_DRC() for( int ii = 0; ii < m_ignoredList->GetItemCount(); ++ii ) g_lastIgnored.push_back( m_ignoredList->GetItemText( ii ) ); - PCBNEW_SETTINGS* settings = m_frame->GetPcbNewSettings(); - settings->m_DrcDialog.refill_zones = m_cbRefillZones->GetValue(); - settings->m_DrcDialog.test_all_track_errors = m_cbReportAllTrackErrors->GetValue(); + PCBNEW_SETTINGS* cfg = nullptr; - if( !Kiface().IsSingle() ) - settings->m_DrcDialog.test_footprints = m_cbTestFootprints->GetValue(); + try + { + cfg = m_frame->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } - settings->m_DrcDialog.severities = m_severities; + if( cfg ) + { + cfg->m_DrcDialog.refill_zones = m_cbRefillZones->GetValue(); + cfg->m_DrcDialog.test_all_track_errors = m_cbReportAllTrackErrors->GetValue(); + + if( !Kiface().IsSingle() ) + cfg->m_DrcDialog.test_footprints = m_cbTestFootprints->GetValue(); + + cfg->m_DrcDialog.severities = m_severities; + } m_markersTreeModel->DecRef(); m_unconnectedTreeModel->DecRef(); diff --git a/pcbnew/dialogs/dialog_export_idf.cpp b/pcbnew/dialogs/dialog_export_idf.cpp index 0f5ebe7451..1449454960 100644 --- a/pcbnew/dialogs/dialog_export_idf.cpp +++ b/pcbnew/dialogs/dialog_export_idf.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2015 Cirilo Bernardo - * Copyright (C) 2013-2019 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2013-2023 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -91,13 +91,25 @@ public: { m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1; - auto cfg = m_parent->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_ExportIdf.units_mils = m_idfThouOpt; - cfg->m_ExportIdf.auto_adjust = m_AutoAdjust; - cfg->m_ExportIdf.ref_units = m_RefUnits; - cfg->m_ExportIdf.ref_x = m_XRef; - cfg->m_ExportIdf.ref_y = m_YRef; + try + { + cfg = m_parent->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + cfg->m_ExportIdf.units_mils = m_idfThouOpt; + cfg->m_ExportIdf.auto_adjust = m_AutoAdjust; + cfg->m_ExportIdf.ref_units = m_RefUnits; + cfg->m_ExportIdf.ref_x = m_XRef; + cfg->m_ExportIdf.ref_y = m_YRef; + } } bool GetThouOption() diff --git a/pcbnew/dialogs/dialog_export_step.cpp b/pcbnew/dialogs/dialog_export_step.cpp index 52dc4ae1af..3bccaabaa0 100644 --- a/pcbnew/dialogs/dialog_export_step.cpp +++ b/pcbnew/dialogs/dialog_export_step.cpp @@ -255,23 +255,35 @@ DIALOG_EXPORT_STEP::~DIALOG_EXPORT_STEP() { GetOriginOption(); // Update m_origin member. - PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_ExportStep.origin_mode = static_cast( m_origin ); - cfg->m_ExportStep.origin_units = m_STEP_OrgUnitChoice->GetSelection(); - cfg->m_ExportStep.replace_models = m_cbSubstModels->GetValue(); - cfg->m_ExportStep.overwrite_file = m_cbOverwriteFile->GetValue(); + try + { + cfg = m_parent->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } - double val = 0.0; + if( cfg ) + { + cfg->m_ExportStep.origin_mode = static_cast( m_origin ); + cfg->m_ExportStep.origin_units = m_STEP_OrgUnitChoice->GetSelection(); + cfg->m_ExportStep.replace_models = m_cbSubstModels->GetValue(); + cfg->m_ExportStep.overwrite_file = m_cbOverwriteFile->GetValue(); - m_STEP_Xorg->GetValue().ToDouble( &val ); - cfg->m_ExportStep.origin_x = val; + double val = 0.0; - m_STEP_Yorg->GetValue().ToDouble( &val ); - cfg->m_ExportStep.origin_y = val; + m_STEP_Xorg->GetValue().ToDouble( &val ); + cfg->m_ExportStep.origin_x = val; - cfg->m_ExportStep.no_unspecified = m_cbRemoveUnspecified->GetValue(); - cfg->m_ExportStep.no_dnp = m_cbRemoveDNP->GetValue(); + m_STEP_Yorg->GetValue().ToDouble( &val ); + cfg->m_ExportStep.origin_y = val; + + cfg->m_ExportStep.no_unspecified = m_cbRemoveUnspecified->GetValue(); + cfg->m_ExportStep.no_dnp = m_cbRemoveDNP->GetValue(); + } m_toleranceLastChoice = m_choiceTolerance->GetSelection(); m_exportTracks = m_cbExportTracks->GetValue(); diff --git a/pcbnew/dialogs/dialog_export_svg.cpp b/pcbnew/dialogs/dialog_export_svg.cpp index 60355659b8..57e7eb1359 100644 --- a/pcbnew/dialogs/dialog_export_svg.cpp +++ b/pcbnew/dialogs/dialog_export_svg.cpp @@ -71,8 +71,6 @@ private: }; -/* DIALOG_EXPORT_SVG functions -*/ DIALOG_EXPORT_SVG::DIALOG_EXPORT_SVG( PCB_EDIT_FRAME* aParent, BOARD* aBoard ) : DIALOG_EXPORT_SVG_BASE( aParent ), m_board( aBoard ), @@ -117,28 +115,42 @@ DIALOG_EXPORT_SVG::~DIALOG_EXPORT_SVG() m_parent->Prj().GetProjectFile().m_PcbLastPath[ LAST_PATH_SVG ] = m_outputDirectory; - auto cfg = m_parent->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_ExportSvg.black_and_white = m_printBW; - cfg->m_ExportSvg.mirror = m_printMirror; - cfg->m_ExportSvg.one_file = m_oneFileOnly; - cfg->m_ExportSvg.page_size = m_rbSvgPageSizeOpt->GetSelection(); - cfg->m_ExportSvg.output_dir = m_outputDirectory.ToStdString(); + try + { + cfg = m_parent->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } - cfg->m_ExportSvg.use_selected_theme = !m_cbUsedBoardTheme->GetValue(); - cfg->m_ExportSvg.color_theme = m_colorTheme->GetStringSelection(); + if( cfg ) + { + cfg->m_ExportSvg.black_and_white = m_printBW; + cfg->m_ExportSvg.mirror = m_printMirror; + cfg->m_ExportSvg.one_file = m_oneFileOnly; + cfg->m_ExportSvg.page_size = m_rbSvgPageSizeOpt->GetSelection(); + cfg->m_ExportSvg.output_dir = m_outputDirectory.ToStdString(); + cfg->m_ExportSvg.use_selected_theme = !m_cbUsedBoardTheme->GetValue(); + cfg->m_ExportSvg.color_theme = m_colorTheme->GetStringSelection(); + } if( m_checkboxPagePerLayer->GetValue() ) { m_oneFileOnly = false; - cfg->m_ExportSvg.plot_board_edges = m_checkboxEdgesOnAllPages->GetValue(); + + if( cfg ) + cfg->m_ExportSvg.plot_board_edges = m_checkboxEdgesOnAllPages->GetValue(); } else { m_oneFileOnly = true; } - cfg->m_ExportSvg.layers.clear(); + if( cfg ) + cfg->m_ExportSvg.layers.clear(); for( unsigned layer = 0; layer < arrayDim( m_boxSelectLayer ); ++layer ) { @@ -146,7 +158,10 @@ DIALOG_EXPORT_SVG::~DIALOG_EXPORT_SVG() continue; if( m_boxSelectLayer[layer].first->IsChecked( m_boxSelectLayer[layer].second ) ) - cfg->m_ExportSvg.layers.push_back( layer ); + { + if( cfg ) + cfg->m_ExportSvg.layers.push_back( layer ); + } } } @@ -302,6 +317,7 @@ void DIALOG_EXPORT_SVG::ExportSVGFile( bool aOnlyOneFile ) LSET all_selected = getCheckBoxSelectedLayers(); PCB_PLOT_SVG_OPTIONS svgPlotOptions; + svgPlotOptions.m_negative = false; svgPlotOptions.m_blackAndWhite = m_printBW; svgPlotOptions.m_printMaskLayer = m_printMaskLayer; svgPlotOptions.m_pageSizeMode = m_rbSvgPageSizeOpt->GetSelection(); diff --git a/pcbnew/dialogs/dialog_export_vrml.cpp b/pcbnew/dialogs/dialog_export_vrml.cpp index 8a687053cf..94d3926478 100644 --- a/pcbnew/dialogs/dialog_export_vrml.cpp +++ b/pcbnew/dialogs/dialog_export_vrml.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2013 Lorenzo Mercantonio * Copyright (C) 2013 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2023 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -96,20 +96,32 @@ public: m_unitsOpt = GetUnits(); m_copy3DFilesOpt = GetCopyFilesOption(); - PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_ExportVrml.units = m_unitsOpt; - cfg->m_ExportVrml.copy_3d_models = m_copy3DFilesOpt; - cfg->m_ExportVrml.use_relative_paths = m_useRelativePathsOpt; - cfg->m_ExportVrml.ref_units = m_VRML_RefUnitChoice->GetSelection(); - cfg->m_ExportVrml.origin_mode = m_rbCoordOrigin->GetSelection(); + try + { + cfg = m_parent->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } - double val = 0.0; - m_VRML_Xref->GetValue().ToDouble( &val ); - cfg->m_ExportVrml.ref_x = val; + if( cfg ) + { + cfg->m_ExportVrml.units = m_unitsOpt; + cfg->m_ExportVrml.copy_3d_models = m_copy3DFilesOpt; + cfg->m_ExportVrml.use_relative_paths = m_useRelativePathsOpt; + cfg->m_ExportVrml.ref_units = m_VRML_RefUnitChoice->GetSelection(); + cfg->m_ExportVrml.origin_mode = m_rbCoordOrigin->GetSelection(); - m_VRML_Yref->GetValue().ToDouble( &val ); - cfg->m_ExportVrml.ref_y = val; + double val = 0.0; + m_VRML_Xref->GetValue().ToDouble( &val ); + cfg->m_ExportVrml.ref_x = val; + + m_VRML_Yref->GetValue().ToDouble( &val ); + cfg->m_ExportVrml.ref_y = val; + } }; void SetSubdir( const wxString & aDir ) diff --git a/pcbnew/dialogs/dialog_footprint_properties.cpp b/pcbnew/dialogs/dialog_footprint_properties.cpp index 05a036d978..2d56a5b403 100644 --- a/pcbnew/dialogs/dialog_footprint_properties.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties.cpp @@ -176,8 +176,21 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES() { - if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() ) + PCBNEW_SETTINGS* cfg = nullptr; + + try + { + cfg = m_frame->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { cfg->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumnsAsString(); + } // Prevents crash bug in wxGrid's d'tor m_itemsGrid->DestroyTable( m_fields ); diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index 0f50c25495..359a35d483 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -228,8 +228,21 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR() { - if( FOOTPRINT_EDITOR_SETTINGS* cfg = m_frame->GetSettings() ) + PCBNEW_SETTINGS* cfg = nullptr; + + try + { + cfg = m_frame->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { cfg->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumnsAsString(); + } // Prevents crash bug in wxGrid's d'tor m_itemsGrid->DestroyTable( m_fields ); diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp index f97a073175..4d050071f3 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2014 Miguel Angel Ajo - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -68,9 +68,19 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent ) DIALOG_FOOTPRINT_WIZARD_LIST::~DIALOG_FOOTPRINT_WIZARD_LIST() { - if( !IsIconized() ) + PCBNEW_SETTINGS* cfg = nullptr; + + try + { + cfg = Pgm().GetSettingsManager().GetAppSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg && !IsIconized() ) { - auto cfg = Pgm().GetSettingsManager().GetAppSettings(); cfg->m_FootprintWizardList.width = GetSize().x; cfg->m_FootprintWizardList.height = GetSize().y; diff --git a/pcbnew/dialogs/dialog_import_netlist.cpp b/pcbnew/dialogs/dialog_import_netlist.cpp index a91bd90d52..f11e2b5fad 100644 --- a/pcbnew/dialogs/dialog_import_netlist.cpp +++ b/pcbnew/dialogs/dialog_import_netlist.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -91,12 +91,24 @@ DIALOG_IMPORT_NETLIST::~DIALOG_IMPORT_NETLIST() { m_matchByUUID = m_matchByTimestamp->GetSelection() == 0; - PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_NetlistDialog.report_filter = m_MessageWindow->GetVisibleSeverities(); - cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue(); - cfg->m_NetlistDialog.delete_shorting_tracks = m_cbDeleteShortingTracks->GetValue(); - cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue(); + try + { + cfg = m_parent->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + cfg->m_NetlistDialog.report_filter = m_MessageWindow->GetVisibleSeverities(); + cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue(); + cfg->m_NetlistDialog.delete_shorting_tracks = m_cbDeleteShortingTracks->GetValue(); + cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue(); + } if( m_runDragCommand ) { diff --git a/pcbnew/dialogs/dialog_update_pcb.cpp b/pcbnew/dialogs/dialog_update_pcb.cpp index 7b031a3ff7..97a7091863 100644 --- a/pcbnew/dialogs/dialog_update_pcb.cpp +++ b/pcbnew/dialogs/dialog_update_pcb.cpp @@ -68,12 +68,24 @@ DIALOG_UPDATE_PCB::DIALOG_UPDATE_PCB( PCB_EDIT_FRAME* aParent, NETLIST* aNetlist DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB() { - auto cfg = m_frame->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_NetlistDialog.associate_by_ref_sch = m_cbRelinkFootprints->GetValue(); - cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue(); - cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue(); - cfg->m_NetlistDialog.report_filter = m_messagePanel->GetVisibleSeverities(); + try + { + cfg = m_frame->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + cfg->m_NetlistDialog.associate_by_ref_sch = m_cbRelinkFootprints->GetValue(); + cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue(); + cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue(); + cfg->m_NetlistDialog.report_filter = m_messagePanel->GetVisibleSeverities(); + } if( m_runDragCommand ) { diff --git a/pcbnew/import_gfx/dialog_import_gfx_pcb.cpp b/pcbnew/import_gfx/dialog_import_gfx_pcb.cpp index dc51cd8422..5c94fe7976 100644 --- a/pcbnew/import_gfx/dialog_import_gfx_pcb.cpp +++ b/pcbnew/import_gfx/dialog_import_gfx_pcb.cpp @@ -130,15 +130,28 @@ DIALOG_IMPORT_GFX_PCB::DIALOG_IMPORT_GFX_PCB( PCB_BASE_FRAME* aParent, bool aImp DIALOG_IMPORT_GFX_PCB::~DIALOG_IMPORT_GFX_PCB() { - PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings(); + PCBNEW_SETTINGS* cfg = nullptr; - cfg->m_ImportGraphics.layer = m_SelLayerBox->GetLayerSelection(); - cfg->m_ImportGraphics.interactive_placement = m_placementInteractive; - cfg->m_ImportGraphics.last_file = m_textCtrlFileName->GetValue(); - cfg->m_ImportGraphics.dxf_line_width = pcbIUScale.IUTomm( m_defaultLineWidth.GetValue() ); - cfg->m_ImportGraphics.origin_x = pcbIUScale.IUTomm( m_xOrigin.GetValue() ); - cfg->m_ImportGraphics.origin_y = pcbIUScale.IUTomm( m_yOrigin.GetValue() ); - cfg->m_ImportGraphics.dxf_units = m_choiceDxfUnits->GetSelection(); + try + { + cfg = m_parent->GetPcbNewSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) + { + cfg->m_ImportGraphics.layer = m_SelLayerBox->GetLayerSelection(); + cfg->m_ImportGraphics.interactive_placement = m_placementInteractive; + cfg->m_ImportGraphics.last_file = m_textCtrlFileName->GetValue(); + cfg->m_ImportGraphics.dxf_line_width = + pcbIUScale.IUTomm( m_defaultLineWidth.GetValue() ); + cfg->m_ImportGraphics.origin_x = pcbIUScale.IUTomm( m_xOrigin.GetValue() ); + cfg->m_ImportGraphics.origin_y = pcbIUScale.IUTomm( m_yOrigin.GetValue() ); + cfg->m_ImportGraphics.dxf_units = m_choiceDxfUnits->GetSelection(); + } m_importScale = EDA_UNIT_UTILS::UI::DoubleValueFromString( m_importScaleCtrl->GetValue() ); diff --git a/pcbnew/router/pns_item.cpp b/pcbnew/router/pns_item.cpp index 861bb6b628..cca36bad83 100644 --- a/pcbnew/router/pns_item.cpp +++ b/pcbnew/router/pns_item.cpp @@ -240,6 +240,7 @@ bool ITEM::collideSimple( const ITEM* aHead, const NODE* aNode, obs.m_item = const_cast( this ); obs.m_clearance = clearance; obs.m_distFirst = 0; + obs.m_maxFanoutWidth = 0; aCtx->obstacles.insert( obs ); } else diff --git a/pcbnew/router/pns_joint.h b/pcbnew/router/pns_joint.h index cc74f12af9..fbfd194456 100644 --- a/pcbnew/router/pns_joint.h +++ b/pcbnew/router/pns_joint.h @@ -144,9 +144,11 @@ public: if( !via || hasNonVirtualVia ) return false; - assert ( seg1 && seg2 ); + // This compiles away in release builds so we still need to check it below + // to prevent segfaults in release builds. + assert( seg1 && seg2 ); - return seg1->Width() == seg2->Width(); + return ( seg1 && seg2 ) ? seg1->Width() == seg2->Width() : false; } } diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index e3242bde00..3d0520b436 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -143,6 +143,10 @@ const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP, bool aUseClearance ) clearance = m_sizes.Clearance() + m_sizes.DiffPairWidth() / 2; } + PNS::ITEM_SET ret; + + wxCHECK( node, ret ); + if( aUseClearance ) { NODE::OBSTACLES obs; @@ -155,10 +159,6 @@ const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP, bool aUseClearance ) opts.m_differentNetsOnly = false; opts.m_overrideClearance = clearance; - PNS::ITEM_SET ret; - - wxCHECK( node, ret ); - node->QueryColliding( &test, obs, opts ); for( const OBSTACLE& obstacle : obs ) diff --git a/pcbnew/router/pns_walkaround.cpp b/pcbnew/router/pns_walkaround.cpp index ff9db2cb51..180883afd1 100644 --- a/pcbnew/router/pns_walkaround.cpp +++ b/pcbnew/router/pns_walkaround.cpp @@ -188,8 +188,13 @@ const WALKAROUND::RESULT WALKAROUND::Route( const LINE& aInitialPath ) if( s_cw != IN_PROGRESS && s_ccw != IN_PROGRESS ) break; - double lcw = path_cw.Line().Length() / (double)aInitialPath.CLine().Length(); - double lccw = path_ccw.Line().Length() / (double)aInitialPath.CLine().Length(); + double length = (double)aInitialPath.CLine().Length(); + wxCHECK2( length != 0, length = 1.0 ); + double lcw = path_cw.Line().Length() / length; + + length = (double)aInitialPath.CLine().Length(); + wxCHECK2( length != 0, length = 1.0 ); + double lccw = path_ccw.Line().Length() / length; PNS_DBG( Dbg(), Message, wxString::Format( wxT( "lcw %.1f lccw %.1f" ), lcw, lccw ) ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 51d6f8e217..d27cb0e1fb 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -2749,11 +2749,13 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) { ROUTER_TOOL* router = m_frame->GetToolManager()->GetTool(); - m_allowDRCViolations = router->Router()->Settings().AllowDRCViolations(); + if( router ) + m_allowDRCViolations = router->Router()->Settings().AllowDRCViolations(); try { - m_drcEngine->InitEngine( aFrame->GetDesignRulesPath() ); + if( aFrame ) + m_drcEngine->InitEngine( aFrame->GetDesignRulesPath() ); DRC_CONSTRAINT constraint; @@ -2788,6 +2790,8 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) KIGFX::PCB_VIEW* view = m_frame->GetCanvas()->GetView(); std::vector possible_tracks; + wxCHECK( view, nullptr ); + view->Query( bbox, items ); for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : items ) diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 13c93206a0..f4ff961bbd 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -263,7 +263,16 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) while( TOOL_EVENT* evt = Wait() ) { MOUSE_DRAG_ACTION dragAction = m_frame->GetDragAction(); - TRACK_DRAG_ACTION trackDragAction = m_frame->GetPcbNewSettings()->m_TrackDragAction; + TRACK_DRAG_ACTION trackDragAction = TRACK_DRAG_ACTION::MOVE; + + try + { + m_frame->GetPcbNewSettings()->m_TrackDragAction; + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL: setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ), diff --git a/pcbnew/widgets/panel_footprint_chooser.cpp b/pcbnew/widgets/panel_footprint_chooser.cpp index 13ad1be378..cbfd2c2b3a 100644 --- a/pcbnew/widgets/panel_footprint_chooser.cpp +++ b/pcbnew/widgets/panel_footprint_chooser.cpp @@ -167,7 +167,17 @@ PANEL_FOOTPRINT_CHOOSER::~PANEL_FOOTPRINT_CHOOSER() m_dbl_click_timer->Stop(); delete m_dbl_click_timer; - if( PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings() ) + PCBNEW_SETTINGS* cfg = nullptr; + try + { + cfg = Pgm().GetSettingsManager().GetAppSettings(); + } + catch( const std::runtime_error& e ) + { + wxFAIL_MSG( e.what() ); + } + + if( cfg ) { // Save any changes to column widths, etc. m_adapter->SaveSettings();