Commit 3fb3307b authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

CppEditor: Fix crash on Creator shutdown

As a consequence of commit 243a6259, the order of destruction of
CppEditorWidget and CppModelManager changed. Since now the
CppEditorWidget is deleted last, we need to check if the model manager
object still exists.

Change-Id: Ie61b4e3ea07b44f99ae6c21c1d8ac7c799f3620d
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 6cf030d8
......@@ -787,6 +787,9 @@ const Macro *CPPEditorWidget::findCanonicalMacro(const QTextCursor &cursor, Docu
void CPPEditorWidget::findUsages()
{
if (!m_modelManager)
return;
SemanticInfo info = m_lastSemanticInfo;
info.snapshot = CppModelManagerInterface::instance()->snapshot();
info.snapshot.insert(info.doc);
......@@ -804,6 +807,9 @@ void CPPEditorWidget::findUsages()
void CPPEditorWidget::renameUsagesNow(const QString &replacement)
{
if (!m_modelManager)
return;
SemanticInfo info = m_lastSemanticInfo;
info.snapshot = CppModelManagerInterface::instance()->snapshot();
info.snapshot.insert(info.doc);
......@@ -938,6 +944,9 @@ void CPPEditorWidget::markSymbols(const QTextCursor &tc, const SemanticInfo &inf
void CPPEditorWidget::renameSymbolUnderCursor()
{
if (!m_modelManager)
return;
CppEditorSupport *edSup = m_modelManager->cppEditorSupport(editor());
updateSemanticInfo(edSup->recalculateSemanticInfo(/* emitSignalWhenFinished = */ false));
abortRename();
......@@ -1031,6 +1040,9 @@ bool CPPEditorWidget::sortedOutline() const
void CPPEditorWidget::updateOutlineNow()
{
if (!m_modelManager)
return;
const Snapshot snapshot = m_modelManager->snapshot();
Document::Ptr document = snapshot.document(editorDocument()->filePath());
......@@ -1123,7 +1135,7 @@ void CPPEditorWidget::updateUses()
m_highlighter.cancel();
// Block premature semantic info calculation when editor is created.
if (m_modelManager->cppEditorSupport(editor())->initialized())
if (m_modelManager && m_modelManager->cppEditorSupport(editor())->initialized())
m_updateUsesTimer->start();
}
......@@ -1592,7 +1604,8 @@ bool CPPEditorWidget::openCppEditorAt(const Link &link, bool inNextSplit)
void CPPEditorWidget::semanticRehighlight(bool force)
{
m_modelManager->cppEditorSupport(editor())->recalculateSemanticInfoDetached(force);
if (m_modelManager)
m_modelManager->cppEditorSupport(editor())->recalculateSemanticInfoDetached(force);
}
void CPPEditorWidget::highlighterStarted(QFuture<TextEditor::HighlightingResult> *highlighter,
......
......@@ -216,7 +216,7 @@ private:
bool handleDocumentationComment(QKeyEvent *e);
bool isStartOfDoxygenComment(const QTextCursor &cursor) const;
CppTools::CppModelManagerInterface *m_modelManager;
QPointer<CppTools::CppModelManagerInterface> m_modelManager;
QComboBox *m_outlineCombo;
CPlusPlus::OverviewModel *m_outlineModel;
......
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