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>
This commit is contained in:
Sérgio Martins 2017-06-06 23:46:06 +01:00 committed by Laszlo Agocs
parent e8ea1edd89
commit 0265a23bb0
2 changed files with 6 additions and 2 deletions

View File

@ -5622,13 +5622,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();

View File

@ -233,6 +233,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()