From 4a54ea3b119a6f9ee4fe855754f2a0ecb56e770a Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Wed, 9 Aug 2023 07:17:56 -0400 Subject: [PATCH] Try and fix multi-threading issues with the background job widgets Fixes https://gitlab.com/kicad/code/kicad/-/issues/15377 --- common/background_jobs_monitor.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/common/background_jobs_monitor.cpp b/common/background_jobs_monitor.cpp index 81113fd5ee..4c925fb036 100644 --- a/common/background_jobs_monitor.cpp +++ b/common/background_jobs_monitor.cpp @@ -305,26 +305,36 @@ void BACKGROUND_JOBS_MONITOR::ShowList( wxWindow* aParent, wxPoint aPos ) void BACKGROUND_JOBS_MONITOR::jobUpdated( BACKGROUND_JOB* aJob ) { - //for now, we go and update the status bar if its the first job in the vector + // this method is called from the reporters from potentially other threads + // we have to guard ui calls with CallAfter if( m_jobs.size() > 0 ) { + //for now, we go and update the status bar if its the first job in the vector if( m_jobs.front() == aJob ) { // update all status bar entries for( KISTATUSBAR* statusBar : m_statusBars ) { - statusBar->ShowBackgroundProgressBar(); - statusBar->SetBackgroundProgress( aJob->m_currentProgress ); - statusBar->SetBackgroundProgressMax( aJob->m_maxProgress ); - statusBar->SetBackgroundStatusText( aJob->m_status ); + statusBar->CallAfter( + [=]() + { + statusBar->ShowBackgroundProgressBar(); + statusBar->SetBackgroundProgress( aJob->m_currentProgress ); + statusBar->SetBackgroundProgressMax( aJob->m_maxProgress ); + statusBar->SetBackgroundStatusText( aJob->m_status ); + } ); } } } for( BACKGROUND_JOB_LIST* list : m_shownDialogs ) { - list->UpdateJob( aJob ); + list->CallAfter( + [=]() + { + list->UpdateJob( aJob ); + } ); } }