From e8102d85dc1531b6c250460656fe50e08009bc59 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 20 May 2021 16:52:49 +0100 Subject: [PATCH] Shut down fileWatcher more aggresively. While I haven't been able to reproduce the crash, my theory is that those that do are running into situations where wxWidgets defers destructing the window. Fixes https://gitlab.com/kicad/code/kicad/issues/8458 --- kicad/kicad_manager_frame.cpp | 2 -- kicad/project_tree_pane.cpp | 10 +++++++++- kicad/project_tree_pane.h | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index b5013919ab..417eb08c96 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -400,9 +400,7 @@ bool KICAD_MANAGER_FRAME::CloseProject( bool aSave ) mgr.TriggerBackupIfNeeded( NULL_REPORTER::GetInstance() ); if( aSave ) - { mgr.SaveProject(); - } m_active_project = false; mgr.UnloadProject( &Prj() ); diff --git a/kicad/project_tree_pane.cpp b/kicad/project_tree_pane.cpp index c266a95127..bb8f05e561 100644 --- a/kicad/project_tree_pane.cpp +++ b/kicad/project_tree_pane.cpp @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -164,6 +163,12 @@ PROJECT_TREE_PANE::PROJECT_TREE_PANE( KICAD_MANAGER_FRAME* parent ) : PROJECT_TREE_PANE::~PROJECT_TREE_PANE() +{ + shutdownFileWatcher(); +} + + +void PROJECT_TREE_PANE::shutdownFileWatcher() { if( m_watcher ) { @@ -1300,6 +1305,9 @@ void PROJECT_TREE_PANE::FileWatcherReset() void PROJECT_TREE_PANE::EmptyTreePrj() { + // Make sure we don't try to inspect the tree after we've deleted its items. + shutdownFileWatcher(); + m_TreeProject->DeleteAllItems(); } diff --git a/kicad/project_tree_pane.h b/kicad/project_tree_pane.h index 3b1f047f98..519b1aeb5e 100644 --- a/kicad/project_tree_pane.h +++ b/kicad/project_tree_pane.h @@ -155,6 +155,12 @@ private: */ void onIdle( wxIdleEvent &aEvent ); + /** + * Shutdown the file watcher. Used when closing to prevent post-free access into the project + * tree. (Using the destructor doesn't work as wxWidgets defers destruction in some cases.) + */ + void shutdownFileWatcher(); + /** * Function addItemToProjectTree * @brief Add the file or directory aName to the project tree