From 1e263274720ea7b73530bd9f249655f783b56efe Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 10 May 2021 18:05:50 +0200 Subject: [PATCH] Synchronize all started threads in SemanticHighlighter d'tor This fixes a possible crash on session switch or on shutdown. Task-number: QTCREATORBUG-25708 Change-Id: I5dcc2420dca27b9856f47616c6f465ae8f059942 Reviewed-by: Christian Kandeler --- src/plugins/qmljseditor/qmljssemantichighlighter.cpp | 6 ++++-- src/plugins/qmljseditor/qmljssemantichighlighter.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp index b7e98ad0b7c..8fac6e91ec9 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp @@ -560,8 +560,10 @@ void SemanticHighlighter::rerun(const QmlJSTools::SemanticInfo &semanticInfo) m_watcher.cancel(); m_startRevision = m_document->document()->revision(); - m_watcher.setFuture(Utils::runAsync(QThread::LowestPriority, - &SemanticHighlighter::run, this, semanticInfo)); + auto future = Utils::runAsync(QThread::LowestPriority, &SemanticHighlighter::run, + this, semanticInfo); + m_watcher.setFuture(future); + m_futureSynchronizer.addFuture(future); } void SemanticHighlighter::cancel() diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.h b/src/plugins/qmljseditor/qmljssemantichighlighter.h index 77ea2a7c122..ffa45bbaace 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.h +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -89,6 +90,7 @@ private: QHash m_formats; QHash m_extraFormats; QVector m_diagnosticRanges; + QFutureSynchronizer m_futureSynchronizer; }; } // namespace QmlJSEditor