Commit 3b5e84e6 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Fix race condition when closing files

If parse() is called in another thread the CppToolsEditorSupport might be
already destructed.

Task-number: QTCREATORBUG-10548

Change-Id: Ie4215937eb1847b51bce8b080aca4925c0bee39f
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 4c9e3bbe
......@@ -165,6 +165,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
CppEditorSupport::~CppEditorSupport()
{
m_documentParser.cancel();
m_highlighter.cancel();
m_futureSemanticInfo.cancel();
......@@ -278,13 +279,15 @@ void CppEditorSupport::updateDocument()
m_updateDocumentTimer->start(m_updateDocumentInterval);
}
static void parse(QFutureInterface<void> &future, CppEditorSupport *support)
static void parse(QFutureInterface<void> &future, QSharedPointer<SnapshotUpdater> updater)
{
future.setProgressRange(0, 1);
if (future.isCanceled()) {
future.setProgressValue(1);
return;
}
CppModelManager *cmm = qobject_cast<CppModelManager *>(CppModelManager::instance());
QSharedPointer<SnapshotUpdater> updater = support->snapshotUpdater();
updater->update(cmm->workingCopy());
cmm->finishedRefreshingSourceFiles(QStringList(updater->fileInEditor()));
......@@ -304,7 +307,7 @@ void CppEditorSupport::updateDocumentNow()
if (m_highlightingSupport && !m_highlightingSupport->requiresSemanticInfo())
startHighlighting();
m_documentParser = QtConcurrent::run(&parse, this);
m_documentParser = QtConcurrent::run(&parse, snapshotUpdater());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment