From 1a5ebfbe05c3401e33eb5b289766356d634fae80 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 11 Apr 2016 10:18:30 +0200 Subject: [PATCH] Editor: Fix crash when removing mark from the block data destructor. The TextBlockUserData is destructed from QTextBlockData::free which deletes the layout right before. So triggering a direct update from within this destructor could result in a crash when the already deleted layout is used. Task-number: QTCREATORBUG-16046 Change-Id: Ifd1d4334ba8ef47c41e0b9ae078ceaf1112b5908 Reviewed-by: Eike Ziller --- src/plugins/texteditor/textdocument.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 1d1a47a8456..c1fd7545901 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -852,10 +853,16 @@ void TextDocument::removeMarkFromMarksCache(TextMark *mark) QTC_ASSERT(documentLayout, return); d->m_marksCache.removeAll(mark); + auto scheduleLayoutUpdate = [documentLayout](){ + // make sure all destructors that may directly or indirectly call this function are + // completed before updating. + QTimer::singleShot(0, documentLayout, &QPlainTextDocumentLayout::requestUpdate); + }; + if (d->m_marksCache.isEmpty()) { documentLayout->hasMarks = false; documentLayout->maxMarkWidthFactor = 1.0; - documentLayout->requestUpdate(); + scheduleLayoutUpdate(); return; } @@ -879,7 +886,7 @@ void TextDocument::removeMarkFromMarksCache(TextMark *mark) if (maxWidthFactor != documentLayout->maxMarkWidthFactor) { documentLayout->maxMarkWidthFactor = maxWidthFactor; - documentLayout->requestUpdate(); + scheduleLayoutUpdate(); } else { documentLayout->requestExtraAreaUpdate(); }