diff options
author | Sérgio Martins <sergio.martins@kdab.com> | 2017-06-06 23:46:06 +0100 |
---|---|---|
committer | Sérgio Martins <sergio.martins@kdab.com> | 2017-06-08 13:42:14 +0000 |
commit | 58b9f467fc3dbd1c0c4ede92dca7e6509fe248f8 (patch) | |
tree | c343221ce58049d967e5ec52466f00dc66f7ceaa | |
parent | a896d04eead3778377bfcd5c87c37e4461554a74 (diff) |
Fix crash when calling QWidget::grab() on a QOpenGLWidget
By avoiding unneeded nested QPainters.
Crash was:
ASSERT: "s" in file /data/sources/qt/qt5/qtbase/src/gui/painting/qpaintengine_raster.cpp, line 2239
s was nullptr because the inner QPainter had called updateState(0), which is then dereferenced by the outer QPainter.
Task-number: QTBUG-61036
Change-Id: I7aad648f805f1abac4d38dfbefa2292da8b52af4
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit 0265a23bb02b68534bb3c86514cc93bc45a7444f)
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 6 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp | 2 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 53b39e0394..5dd43390ee 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5592,13 +5592,15 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP // punch a hole in the backingstore, so the texture will be visible. if (!q->testAttribute(Qt::WA_AlwaysStackOnTop)) { beginBackingStorePainting(); - QPainter p(q); if (backingStore) { + QPainter p(q); p.setCompositionMode(QPainter::CompositionMode_Source); p.fillRect(q->rect(), Qt::transparent); } else { + QImage img = grabFramebuffer(); + QPainter p(q); // We are not drawing to a backingstore: fall back to QImage - p.drawImage(q->rect(), grabFramebuffer()); + p.drawImage(q->rect(), img); skipPaintEvent = true; } endBackingStorePainting(); diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp index f5c127a063..ca4488744f 100644 --- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp +++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp @@ -228,6 +228,8 @@ void tst_QOpenGLWidget::painter() glw->m_clear = true; image = glw->grabFramebuffer(); QVERIFY(image.pixel(20, 10) == qRgb(0, 255, 0)); + + QPixmap pix = glw->grab(); // QTBUG-61036 } void tst_QOpenGLWidget::reparentToAlreadyCreated() |