From 940570e9ec6614127f72c498bd1328409fde7d14 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 13 Jul 2020 21:21:34 +0100 Subject: [PATCH] Catch exception so that we at least throw up an error message. Fixes https://gitlab.com/kicad/code/kicad/issues/4677 --- common/footprint_info.cpp | 8 +------- common/kiway.cpp | 36 +++++++++++++++++++--------------- common/tool/common_control.cpp | 3 +-- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index daec55e03b..e8d0d722d4 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -116,20 +116,14 @@ static FOOTPRINT_LIST* get_instance_from_id( KIWAY& aKiway, int aId ) { KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB ); - if( !kiface ) - return nullptr; - ptr = kiface->IfaceOrAddress( aId ); - if( !ptr ) - return nullptr; + return static_cast( ptr ); } catch( ... ) { return nullptr; } - - return static_cast( ptr ); } diff --git a/common/kiway.cpp b/common/kiway.cpp index 2099177e95..4823c00985 100644 --- a/common/kiway.cpp +++ b/common/kiway.cpp @@ -36,7 +36,7 @@ #include #include #include - +#include KIFACE* KIWAY::m_kiface[KIWAY_FACE_COUNT]; int KIWAY::m_kiface_version[KIWAY_FACE_COUNT]; @@ -360,27 +360,31 @@ KIWAY_PLAYER* KIWAY::Player( FRAME_T aFrameType, bool doCreate, wxTopLevelWindow if( doCreate ) { - FACE_T face_type = KifaceType( aFrameType ); - wxASSERT( face_type != FACE_T(-1) ); - - KIFACE* kiface = KiFACE( face_type ); - wxASSERT( kiface ); - - if( kiface ) + try { + FACE_T face_type = KifaceType( aFrameType ); + KIFACE* kiface = KiFACE( face_type ); + frame = (KIWAY_PLAYER*) kiface->CreateWindow( - aParent, // Parent window of frame in modal mode, NULL in non modal mode - aFrameType, - this, - m_ctl // questionable need, these same flags where passed - // to the KIFACE::OnKifaceStart() - ); - wxASSERT( frame ); + aParent, // Parent window of frame in modal mode, + // NULL in non modal mode + aFrameType, + this, + m_ctl // questionable need, these same flags + // were passed to KIFACE::OnKifaceStart() + ); m_playerFrameName[aFrameType] = frame->GetName(); - return frame; } + catch( const IO_ERROR& ioe ) + { + DisplayErrorMessage( NULL, _( "Error loading editor" ), ioe.What() ); + } + catch( ... ) + { + DisplayErrorMessage( NULL, _( "Error loading editor" ) ); + } } return NULL; diff --git a/common/tool/common_control.cpp b/common/tool/common_control.cpp index 69143dc07b..f0b4114d17 100644 --- a/common/tool/common_control.cpp +++ b/common/tool/common_control.cpp @@ -92,7 +92,7 @@ int COMMON_CONTROL::ConfigurePaths( const TOOL_EVENT& aEvent ) // Do nothing here. // A error message is displayed after trying to load _pcbnew.kiface. } -} + } else { DIALOG_CONFIGURE_PATHS dlg( m_frame, nullptr ); @@ -101,7 +101,6 @@ int COMMON_CONTROL::ConfigurePaths( const TOOL_EVENT& aEvent ) m_frame->Kiway().CommonSettingsChanged( true ); } - return 0; }