From 6cfe5df7c08aa540b1505e7cd82dd6f9cc82b752 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Tue, 13 Jan 2026 00:56:54 +0500 Subject: [PATCH] Fix crash when CallAfter is called while destructing thread pool on exit. PROJECT_TREE_PANE is already destructed at that point. --- kicad/project_tree_pane.cpp | 10 ++++++++-- kicad/project_tree_pane.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kicad/project_tree_pane.cpp b/kicad/project_tree_pane.cpp index 7b13c3bc6d..7a9aad0ad9 100644 --- a/kicad/project_tree_pane.cpp +++ b/kicad/project_tree_pane.cpp @@ -230,6 +230,12 @@ PROJECT_TREE_PANE::~PROJECT_TREE_PANE() Unbind( wxEVT_TIMER, wxTimerEventHandler( PROJECT_TREE_PANE::onGitStatusTimer ), this, m_gitStatusTimer.GetId() ); shutdownFileWatcher(); + + if( m_gitSyncTask.valid() ) + m_gitSyncTask.wait(); + + if( m_gitStatusIconTask.valid() ) + m_gitStatusIconTask.wait(); } @@ -2709,7 +2715,7 @@ void PROJECT_TREE_PANE::onGitSyncTimer( wxTimerEvent& aEvent ) thread_pool& tp = GetKiCadThreadPool(); - tp.push_task( + m_gitSyncTask = tp.submit( [this]() { KIGIT_COMMON* gitCommon = m_TreeProject->GitCommon(); @@ -2743,7 +2749,7 @@ void PROJECT_TREE_PANE::gitStatusTimerHandler() updateTreeCache(); thread_pool& tp = GetKiCadThreadPool(); - tp.push_task( + m_gitStatusIconTask = tp.submit( [this]() { updateGitStatusIconMap(); diff --git a/kicad/project_tree_pane.h b/kicad/project_tree_pane.h index 16ebbf927c..5f7670e445 100644 --- a/kicad/project_tree_pane.h +++ b/kicad/project_tree_pane.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -322,6 +323,8 @@ private: wxString m_gitCurrentBranchName; wxTimer m_gitSyncTimer; wxTimer m_gitStatusTimer; + std::future m_gitSyncTask; + std::future m_gitStatusIconTask; std::mutex m_gitTreeCacheMutex; std::unordered_map m_gitTreeCache;