From cabf7d4878a9051939f9c3cd84657226139e627e Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Fri, 5 Jul 2024 02:15:20 +0300 Subject: [PATCH] IPC_API: fix crash in PLUGIN_AVAILABILITY_CHANGED event handler (schematic) Re-opening SCH while the PCB is open leads to crash. Same as 441b2686d3150b1c3e0629c3d49857f1c47e3871, but for schematic editor. --- eeschema/sch_edit_frame.cpp | 22 ++++++++++++++++------ eeschema/sch_edit_frame.h | 4 ++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index e234bfa153..f08abcc16c 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -189,12 +189,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : #ifdef KICAD_IPC_API wxTheApp->Bind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, - [&]( wxCommandEvent& aEvt ) - { - wxLogTrace( traceApi, "SCH frame: EDA_EVT_PLUGIN_AVAILABILITY_CHANGED" ); - ReCreateHToolbar(); - aEvt.Skip(); - } ); + &SCH_EDIT_FRAME::onPluginAvailabilityChanged, this ); #endif m_hierarchy = new HIERARCHY_PANE( this ); @@ -429,6 +424,12 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SCH_EDIT_FRAME::~SCH_EDIT_FRAME() { +#ifdef KICAD_IPC_API + Pgm().GetApiServer().DeregisterHandler( m_apiHandler.get() ); + wxTheApp->Unbind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, + &SCH_EDIT_FRAME::onPluginAvailabilityChanged, this ); +#endif + m_hierarchy->Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::OnResizeHierarchyNavigator, this ); // Ensure m_canvasType is up to date, to save it in config @@ -2553,3 +2554,12 @@ void SCH_EDIT_FRAME::updateSelectionFilterVisbility() selectionFilterPane.Show( showFilter ); } + +#ifdef KICAD_IPC_API +void SCH_EDIT_FRAME::onPluginAvailabilityChanged( wxCommandEvent& aEvt ) +{ + wxLogTrace( traceApi, "SCH frame: EDA_EVT_PLUGIN_AVAILABILITY_CHANGED" ); + ReCreateHToolbar(); + aEvt.Skip(); +} +#endif diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 6b4fe77eb5..5632447021 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -923,6 +923,10 @@ protected: void updateSelectionFilterVisbility() override; +#ifdef KICAD_IPC_API + void onPluginAvailabilityChanged( wxCommandEvent& aEvt ); +#endif + private: // Called when resizing the Hierarchy Navigator panel void OnResizeHierarchyNavigator( wxSizeEvent& aEvent );