forked from qt-creator/qt-creator
CppEditor: Use QPointer to 'this' for refactoringEngine calls
RefactoringEngine does not depend on CppEditorWidget therefore we should check that the pointer is still valid in the lambda calls. Hopefully fixes QTCREATORBUG-20111 though this fix does not directly address the stack trace. Task-number: QTCREATORBUG-20111 Change-Id: I37f996de60cebe61e290fe181d75fb266f93c1c1 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -434,10 +434,14 @@ void CppEditorWidget::findUsages(QTextCursor cursor)
|
|||||||
{
|
{
|
||||||
if (cursor.isNull())
|
if (cursor.isNull())
|
||||||
cursor = textCursor();
|
cursor = textCursor();
|
||||||
|
// 'this' in cursorInEditor is never used (and must never be used) asynchronously.
|
||||||
const CppTools::CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this};
|
const CppTools::CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this};
|
||||||
|
QPointer<CppEditorWidget> cppEditorWidget = this;
|
||||||
refactoringEngine().findUsages(cursorInEditor,
|
refactoringEngine().findUsages(cursorInEditor,
|
||||||
[this, cursor](const CppTools::Usages &usages) {
|
[=](const CppTools::Usages &usages) {
|
||||||
findRenameCallback(this, cursor, usages);
|
if (!cppEditorWidget)
|
||||||
|
return;
|
||||||
|
findRenameCallback(cppEditorWidget.data(), cursor, usages);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,10 +450,13 @@ void CppEditorWidget::renameUsages(const QString &replacement, QTextCursor curso
|
|||||||
if (cursor.isNull())
|
if (cursor.isNull())
|
||||||
cursor = textCursor();
|
cursor = textCursor();
|
||||||
CppTools::CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this};
|
CppTools::CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this};
|
||||||
|
QPointer<CppEditorWidget> cppEditorWidget = this;
|
||||||
refactoringEngine().globalRename(cursorInEditor,
|
refactoringEngine().globalRename(cursorInEditor,
|
||||||
[this, cursor, &replacement](const CppTools::Usages &usages) {
|
[=](const CppTools::Usages &usages) {
|
||||||
findRenameCallback(this, cursor, usages, true,
|
if (!cppEditorWidget)
|
||||||
replacement);
|
return;
|
||||||
|
findRenameCallback(cppEditorWidget.data(), cursor, usages,
|
||||||
|
true, replacement);
|
||||||
},
|
},
|
||||||
replacement);
|
replacement);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user