tdf#163697: avoid premature handling of following notifications

This avoids re-entry to Document::handleParagraphNotifications, which
already was known to be problematic (see comments in Document::Notify,
and m_bSelectionChangedNotification introduced to avoid one such case).

Change-Id: I9e0b451f13ad109d08b1afc9cc0346cd6049b026
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175879
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Mike Kaganski 2024-10-31 20:46:56 +05:00
parent 15eb26d0f2
commit 9a07b6c34c
2 changed files with 12 additions and 0 deletions

View File

@ -572,6 +572,7 @@ private:
std::queue< ::TextHint > m_aParagraphNotifications;
bool m_bSelectionChangedNotification;
bool m_bInParagraphNotificationsHandler = false;
};
}

View File

@ -1670,6 +1670,16 @@ Document::changeParagraphText(::sal_uInt32 nNumber, ::sal_uInt16 nBegin, ::sal_u
void Document::handleParagraphNotifications()
{
// Recursion is possible, e.g. when SfxHintId::TextParaInserted is being handled,
// and TextEngine::GetTextHeight is called for the paragraph being inserted; that
// tries to handle the following SfxHintId::TextFormatPara notification at the
// moment when the respective element hasn't yet been inserted into m_aParagraphs,
// which could crash. Therefore, re-entry is not allowed. The handling is done in
// a loop anyway, so it will process all of them in due order.
// See also comments in Document::Notify.
if (m_bInParagraphNotificationsHandler)
return;
m_bInParagraphNotificationsHandler = true;
while (!m_aParagraphNotifications.empty())
{
::TextHint aHint(m_aParagraphNotifications.front());
@ -1856,6 +1866,7 @@ void Document::handleParagraphNotifications()
break;
}
}
m_bInParagraphNotificationsHandler = false;
if (m_bSelectionChangedNotification)
{
m_bSelectionChangedNotification = false;