From fc26cdfb7423f1e2b902e3b30b77215b73413a1f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 5 May 2014 09:46:07 +0200 Subject: [PATCH] footprint editor: fix crashes. In this fix, I removed the assumption the parent frame is the board editor. However, this assumption is still present here and there in the moduleframe code. --- pcbnew/loadcmp.cpp | 9 ++++++--- pcbnew/moduleframe.cpp | 17 +++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index 3aca4d620f..6e66b00c55 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -65,14 +65,17 @@ static FOOTPRINT_LIST MList; bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule ) { MODULE* newModule; - PCB_BASE_FRAME* parent = (PCB_BASE_FRAME*) GetParent(); + PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); + + if( frame == NULL ) // happens if no board editor opened + return false; if( aModule == NULL ) { - if( ! parent->GetBoard() || ! parent->GetBoard()->m_Modules ) + if( ! frame->GetBoard() || ! frame->GetBoard()->m_Modules ) return false; - aModule = SelectFootprint( parent->GetBoard() ); + aModule = SelectFootprint( frame->GetBoard() ); } if( aModule == NULL ) diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index c2a9b93d4e..076dc14999 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -50,6 +50,7 @@ #include #include #include +#include static PCB_SCREEN* s_screenModule; // the PCB_SCREEN used by the footprint editor @@ -416,21 +417,21 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateLibAndModuleSelected( wxUpdateUIEvent& aEvent void FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard( wxUpdateUIEvent& aEvent ) { - PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) GetParent(); + PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); - aEvent.Enable( frame->GetBoard()->m_Modules != NULL ); + aEvent.Enable( frame && frame->GetBoard()->m_Modules != NULL ); } void FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent ) { - PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) GetParent(); + PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); MODULE* module_in_edit = GetBoard()->m_Modules; - bool canInsert = ( module_in_edit && !module_in_edit->GetLink() ); + bool canInsert = frame && module_in_edit && !module_in_edit->GetLink(); // If the source was deleted, the module can inserted but not updated in the board. - if( module_in_edit && module_in_edit->GetLink() ) // this is not a new module + if( frame && module_in_edit && module_in_edit->GetLink() ) // this is not a new module { BOARD* mainpcb = frame->GetBoard(); MODULE* source_module = mainpcb->m_Modules; @@ -451,12 +452,12 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent void FOOTPRINT_EDIT_FRAME::OnUpdateReplaceModuleInBoard( wxUpdateUIEvent& aEvent ) { - PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) GetParent(); + PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); MODULE* module_in_edit = GetBoard()->m_Modules; - bool canReplace = ( module_in_edit && module_in_edit->GetLink() ); + bool canReplace = frame && module_in_edit && module_in_edit->GetLink(); - if( module_in_edit && module_in_edit->GetLink() ) // this is not a new module + if( canReplace ) // this is not a new module, but verify if the source is still on board { BOARD* mainpcb = frame->GetBoard(); MODULE* source_module = mainpcb->m_Modules;