From a6a2dae480cbc1ba8b7f47129e14ebbed328bdc9 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 31 Dec 2020 10:53:14 +0100 Subject: [PATCH] Footprint editor: ensure the pad editor is closed before load a new footprint. When editing a new footprint from the board editor, if the Footprint editor has the pad editor open, there is a risk of crash when replacing the footprint in edit. Fixes #6892 https://gitlab.com/kicad/code/kicad/issues/6892 --- pcbnew/dialogs/dialog_pad_properties.cpp | 2 ++ pcbnew/dialogs/dialog_pad_properties.h | 3 +++ pcbnew/load_select_footprint.cpp | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index c65dfb870a..a14fd101d0 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -135,6 +135,8 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad m_spokeWidth( aParent, m_spokeWidthLabel, m_spokeWidthCtrl, m_spokeWidthUnits, true ), m_thermalGap( aParent, m_thermalGapLabel, m_thermalGapCtrl, m_thermalGapUnits, true ) { + SetName( PAD_PROPERTIES_DLG_NAME ); + m_currentPad = aPad; // aPad can be NULL, if the dialog is called // from the footprint editor to set default pad setup diff --git a/pcbnew/dialogs/dialog_pad_properties.h b/pcbnew/dialogs/dialog_pad_properties.h index 09034173fd..df2ce6d93a 100644 --- a/pcbnew/dialogs/dialog_pad_properties.h +++ b/pcbnew/dialogs/dialog_pad_properties.h @@ -44,6 +44,9 @@ * DIALOG_PAD_PROPERTIES, derived from DIALOG_PAD_PROPERTIES_BASE, * created by wxFormBuilder */ +// The wxWidgets window name. Used to retrieve the dialog by window name +#define PAD_PROPERTIES_DLG_NAME "pad_properties_dlg_name" + class DIALOG_PAD_PROPERTIES : public DIALOG_PAD_PROPERTIES_BASE { public: diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index df155666cd..e68a3a30a4 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -51,6 +51,7 @@ using namespace std::placeholders; #include #include #include +#include #include "fp_tree_model_adapter.h" @@ -98,6 +99,12 @@ bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( FOOTPRINT* aFootprint ) if( aFootprint == NULL ) return false; + // Ensure we do not have the pad editor open (that is apseudo modal dlg). + // LoadFootprintFromBoard() can be called from the board editor, and we must ensure + // no footprint item is currently in edit + if( wxWindow::FindWindowByName( PAD_PROPERTIES_DLG_NAME ) ) + wxWindow::FindWindowByName( PAD_PROPERTIES_DLG_NAME )->Close(); + if( !Clear_Pcb( true ) ) return false;