From 2fc0cd68ed3b92926b34f04bb6c658185a1faed1 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Wed, 7 Dec 2022 23:55:47 -0500 Subject: [PATCH] Avoid crashing due to empty lib tables in cli Fixes https://gitlab.com/kicad/code/kicad/-/issues/13097 --- common/confirm.cpp | 19 +++++++++++++++++++ eeschema/eeschema.cpp | 16 ++++++++++------ include/kiway.h | 5 +++-- kicad/kicad_cli.cpp | 2 +- pcbnew/pcbnew.cpp | 8 ++++++-- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/common/confirm.cpp b/common/confirm.cpp index a6fe6295a6..fa9730fb5e 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -285,6 +286,12 @@ void DisplayError( wxWindow* aParent, const wxString& aText, int aDisplayTime ) return; } + if( !wxTheApp->IsGUI() ) + { + wxFprintf( stderr, aText ); + return; + } + wxMessageDialog* dlg; int icon = aDisplayTime > 0 ? wxICON_INFORMATION : wxICON_ERROR; @@ -304,6 +311,12 @@ void DisplayErrorMessage( wxWindow* aParent, const wxString& aText, const wxStri return; } + if( !wxTheApp->IsGUI() ) + { + wxFprintf( stderr, aText ); + return; + } + wxMessageDialog* dlg; dlg = new wxMessageDialog( aParent, aText, _( "Error" ), @@ -325,6 +338,12 @@ void DisplayInfoMessage( wxWindow* aParent, const wxString& aMessage, const wxSt return; } + if( !wxTheApp->IsGUI() ) + { + wxFprintf( stdout, "%s %s", aMessage, aExtraInfo ); + return; + } + wxMessageDialog* dlg; int icon = wxICON_INFORMATION; diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 4f7aca4d4a..5cb8734098 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -61,6 +61,8 @@ #include #include +#include + // The main sheet of the project SCH_SHEET* g_RootSheet = nullptr; @@ -341,9 +343,12 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) if( !fn.FileExists() ) { - DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( nullptr ); + if( !( aCtlBits & KFCTL_CLI ) ) + { + DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( nullptr ); - fpDialog.ShowModal(); + fpDialog.ShowModal(); + } } else { @@ -360,10 +365,9 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) // if we are here, a incorrect global symbol library table was found. // Incorrect global symbol library table is not a fatal error: // the user just has to edit the (partially) loaded table. - wxString msg = _( - "An error occurred attempting to load the global symbol library table.\n" - "Please edit this global symbol library table in Preferences menu." - ); + wxString msg = + _( "An error occurred attempting to load the global symbol library table.\n" + "Please edit this global symbol library table in Preferences menu." ); DisplayErrorMessage( nullptr, msg, ioe.What() ); } diff --git a/include/kiway.h b/include/kiway.h index f14cfd1947..def73ba60e 100644 --- a/include/kiway.h +++ b/include/kiway.h @@ -155,8 +155,9 @@ struct KIFACE virtual ~KIFACE() throw() {} -#define KFCTL_STANDALONE (1<<0) ///< Running as a standalone Top. -#define KFCTL_CPP_PROJECT_SUITE (1<<1) ///< Running under C++ project mgr, possibly with others. +#define KFCTL_STANDALONE ( 1 << 0 ) ///< Running as a standalone Top. +#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 ) ///< Running under C++ project mgr, possibly with others. +#define KFCTL_CLI ( 1 << 2 ) ///< Running as CLI app /** diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 8ad6c033c8..a43ceecd2c 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -357,7 +357,7 @@ void PGM_KICAD::Destroy() } -KIWAY Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE ); +KIWAY Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE | KFCTL_CLI ); /** diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 3bb10b3bcb..c2ea27857e 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -62,6 +62,7 @@ #include #include "pcbnew_jobs_handler.h" +#include /* init functions defined by swig */ @@ -350,9 +351,12 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) if( !fn.FileExists() ) { - DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG fpDialog( nullptr ); + if( !( aCtlBits & KFCTL_CLI ) ) + { + DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG fpDialog( nullptr ); - fpDialog.ShowModal(); + fpDialog.ShowModal(); + } } else {