From dc789e34bd2ff519024af077bebdf09c85e138e0 Mon Sep 17 00:00:00 2001 From: Trond Kjernaasen Date: Mon, 2 Mar 2009 13:17:40 +0100 Subject: Fixes: Crash in QPixmap under X11. Task: 246446 RevBy: Olivier AutoTest: tst_qpixmap::test_246446() Details: The new QX11PixmapData object wasn't referenced (e.g. the ref count would be 0) after calling setMask() on a 32 bit QPixmap when Xrender was used. --- src/gui/image/qpixmap_x11.cpp | 6 ++++++ src/gui/image/qpixmapdata_p.h | 1 + tests/auto/qpixmap/tst_qpixmap.cpp | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index d758221..ff7c1b6 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -1288,6 +1288,12 @@ void QX11PixmapData::setMask(const QBitmap &newmask) 0, 0, 0, 0, 0, 0, w, h); release(); *this = newData; + // the new QX11PixmapData object isn't referenced yet, so + // ref it + ref.ref(); + + // the below is to make sure the QX11PixmapData destructor + // doesn't delete our newly created render picture newData.hd = 0; newData.x11_mask = 0; newData.picture = 0; diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 2e4da40..7296426 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -109,6 +109,7 @@ protected: private: friend class QPixmap; friend class QGLContextPrivate; + friend class QX11PixmapData; QAtomicInt ref; int detach_no; diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 2b337da..ba117d8 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -103,6 +103,7 @@ private slots: void grabWidget(); void grabWindow(); void isNull(); + void task_246446(); #ifdef Q_WS_QWS void convertFromImageNoDetach(); @@ -1015,5 +1016,20 @@ void tst_QPixmap::fromData() QCOMPARE(img.pixel(0, 1), QRgb(0xff000000)); } +void tst_QPixmap::task_246446() +{ + // This crashed without the bugfix in 246446 + QPixmap pm(10, 10); + pm.fill(Qt::transparent); // force 32-bit depth + QBitmap bm; + pm.setMask(bm); + { + QPixmap pm2(pm); + } + QVERIFY(pm.width() == 10); + QVERIFY(pm.mask().isNull()); +} + + QTEST_MAIN(tst_QPixmap) #include "tst_qpixmap.moc" -- cgit v0.12