forked from qt-creator/qt-creator
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:
@@ -185,26 +185,26 @@ 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 == 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()) {
|
if (!processor->running()) {
|
||||||
// do not delete this processor directly since this function is called from within the processor
|
// do not delete this processor directly since this function is called from within the processor
|
||||||
QMetaObject::invokeMethod(QCoreApplication::instance(), [processor] {
|
QMetaObject::invokeMethod(QCoreApplication::instance(), [processor] {
|
||||||
delete processor;
|
delete processor;
|
||||||
}, Qt::QueuedConnection);
|
}, 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)))
|
if (IAssistProposal *newProposal = processor->start(std::move(assistInterface)))
|
||||||
|
|||||||
Reference in New Issue
Block a user