From d63c57ef47fa7de0f7621a4ac8c41131e01905bc Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 22 May 2023 10:12:23 +0200 Subject: [PATCH] CodeAssistant: do not schedule processor deletion too early Calling displayProposal might spawn another eventloop that potentially deletes the processor before the async proposal handler finished. Fixes: QTCREATORBUG-28989 Change-Id: I3a8ddb9180cb7737a37ea39dc59d922e83615ed6 Reviewed-by: Christian Kandeler --- .../texteditor/codeassist/codeassistant.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/plugins/texteditor/codeassist/codeassistant.cpp b/src/plugins/texteditor/codeassist/codeassistant.cpp index b3d9d477e24..182df3002a1 100644 --- a/src/plugins/texteditor/codeassist/codeassistant.cpp +++ b/src/plugins/texteditor/codeassist/codeassistant.cpp @@ -185,26 +185,26 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason, IAssistProcessor *processor = provider->createProcessor(assistInterface.get()); processor->setAsyncCompletionAvailableHandler([this, reason, processor]( IAssistProposal *newProposal) { + if (processor == m_processor) { + invalidateCurrentRequestData(); + if (processor->needsRestart() && m_receivedContentWhileWaiting) { + delete newProposal; + m_receivedContentWhileWaiting = false; + requestProposal(reason, m_assistKind, m_requestProvider); + } else { + displayProposal(newProposal, reason); + if (processor->running()) + m_processor = processor; + else + emit q->finished(); + } + } if (!processor->running()) { // do not delete this processor directly since this function is called from within the processor QMetaObject::invokeMethod(QCoreApplication::instance(), [processor] { delete processor; }, Qt::QueuedConnection); } - if (processor != m_processor) - return; - invalidateCurrentRequestData(); - if (processor->needsRestart() && m_receivedContentWhileWaiting) { - delete newProposal; - m_receivedContentWhileWaiting = false; - requestProposal(reason, m_assistKind, m_requestProvider); - } else { - displayProposal(newProposal, reason); - if (processor->running()) - m_processor = processor; - else - emit q->finished(); - } }); if (IAssistProposal *newProposal = processor->start(std::move(assistInterface)))