summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-24 15:35:57 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-24 09:49:36 -0700
commita9a4249b236f07418a3c678d3ec2b7791f957048 (patch)
tree05d5de6fe07e31df24ac5221131f3a025bab4b1a /desktop-widgets
parent0278f3f90c307bc62c329bef0bf1f5bb6b76635d (diff)
downloadsubsurface-a9a4249b236f07418a3c678d3ec2b7791f957048.tar.gz
desktop: avoid crashes on drag&drop in GroupedLineEdit
If the user manages to "scroll" through the QPlainTextEdit by a drag&drop action, the state of the widget becomes inconsistent. On the one hand, the text-block says that it has one line. On the other hand, its layout says that it has no line. When trying to fetch the line, a crash occurs. Try to detect such a strange state and return early in GroupedLineEdit::paintEvent(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/groupedlineedit.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/desktop-widgets/groupedlineedit.cpp b/desktop-widgets/groupedlineedit.cpp
index fdce55ca4..5639b2e1b 100644
--- a/desktop-widgets/groupedlineedit.cpp
+++ b/desktop-widgets/groupedlineedit.cpp
@@ -161,7 +161,15 @@ void GroupedLineEdit::keyPressEvent(QKeyEvent *e)
void GroupedLineEdit::paintEvent(QPaintEvent *e)
{
- QTextLine line = document()->findBlock(0).layout()->lineAt(0);
+ // Do some sanity checks. Without these, the code may crash if
+ // the user manages to scroll the text box by drag&drop actions.
+ const QTextBlock &block = document()->findBlock(0);
+ if (block.lineCount() <= 0)
+ return QPlainTextEdit::paintEvent(e);
+ const QTextLayout *layout = block.layout();
+ if (layout->lineCount() <= 0)
+ return QPlainTextEdit::paintEvent(e);
+ QTextLine line = layout->lineAt(0);
QPainter painter(viewport());
painter.setRenderHint(QPainter::Antialiasing, true);