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 <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2023-05-22 10:12:23 +02:00
parent 0ddbf9f6b8
commit d63c57ef47

View File

@@ -185,14 +185,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
IAssistProcessor *processor = provider->createProcessor(assistInterface.get()); IAssistProcessor *processor = provider->createProcessor(assistInterface.get());
processor->setAsyncCompletionAvailableHandler([this, reason, processor]( processor->setAsyncCompletionAvailableHandler([this, reason, processor](
IAssistProposal *newProposal) { IAssistProposal *newProposal) {
if (!processor->running()) { if (processor == m_processor) {
// 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(); invalidateCurrentRequestData();
if (processor->needsRestart() && m_receivedContentWhileWaiting) { if (processor->needsRestart() && m_receivedContentWhileWaiting) {
delete newProposal; delete newProposal;
@@ -205,6 +198,13 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
else else
emit q->finished(); 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 (IAssistProposal *newProposal = processor->start(std::move(assistInterface))) if (IAssistProposal *newProposal = processor->start(std::move(assistInterface)))