Tie handler de-registration to window close

The handlers can't accept commands when the window
is closed, which can be (far) earlier than the actual
dtor of the frame

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19375
This commit is contained in:
Jon Evans 2024-12-26 18:26:06 -05:00
parent 6c47f32ccf
commit fb8d16439b
2 changed files with 12 additions and 12 deletions

View File

@ -439,12 +439,6 @@ 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
@ -1054,6 +1048,12 @@ void SCH_EDIT_FRAME::doCloseWindow()
{
SCH_SHEET_LIST sheetlist = Schematic().Hierarchy();
#ifdef KICAD_IPC_API
Pgm().GetApiServer().DeregisterHandler( m_apiHandler.get() );
wxTheApp->Unbind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED,
&SCH_EDIT_FRAME::onPluginAvailabilityChanged, this );
#endif
// Shutdown all running tools
if( m_toolManager )
m_toolManager->ShutdownAllTools();

View File

@ -569,12 +569,6 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
delete m_eventCounterTimer;
}
#ifdef KICAD_IPC_API
Pgm().GetApiServer().DeregisterHandler( m_apiHandler.get() );
wxTheApp->Unbind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED,
&PCB_EDIT_FRAME::onPluginAvailabilityChanged, this );
#endif
// Close modeless dialogs
wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
@ -1198,6 +1192,12 @@ void PCB_EDIT_FRAME::doCloseWindow()
GetCanvas()->StopDrawing();
#ifdef KICAD_IPC_API
Pgm().GetApiServer().DeregisterHandler( m_apiHandler.get() );
wxTheApp->Unbind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED,
&PCB_EDIT_FRAME::onPluginAvailabilityChanged, this );
#endif
// Clean up mode-less dialogs.
Unbind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs,
this );