xcb: Don't crash on missing mouse pointer
authorUli Schlachter <psychon@znc.in>
Sun, 22 Jan 2012 19:41:42 +0000 (20:41 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 23 Jan 2012 10:02:18 +0000 (11:02 +0100)
The draganddrop examples all crashed here because they were using a
default-constructed QImage() (i.e. one without any content).

I guess this happens here because I don't have any mouse theme set.
To test, one could start a second X server, but without any WM or DE.

The "evil" QImage() came from QGuiApplicationPrivate::getPixmapCursor().
This function seems to just always "return QPixmap();".

This fix is correct because the only caller has another fallback if the
createNonStandardCursor()-fallback didn't work. This caller is
QXcbCursor::createFontCursor().

Change-Id: I7ec7fbcfdf0203e983149b5e73016cc7e85ecf40
Signed-off-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/plugins/platforms/xcb/qxcbcursor.cpp

index b92c00a..ac6825a 100644 (file)
@@ -426,10 +426,12 @@ xcb_cursor_t QXcbCursor::createNonStandardCursor(int cshape)
     } else if (cshape == Qt::DragCopyCursor || cshape == Qt::DragMoveCursor
                || cshape == Qt::DragLinkCursor) {
         QImage image = QGuiApplicationPrivate::instance()->getPixmapCursor(static_cast<Qt::CursorShape>(cshape)).toImage();
-        xcb_pixmap_t pm = qt_xcb_XPixmapFromBitmap(m_screen, image);
-        xcb_pixmap_t pmm = qt_xcb_XPixmapFromBitmap(m_screen, image.createAlphaMask());
-        cursor = xcb_generate_id(conn);
-        xcb_create_cursor(conn, cursor, pm, pmm, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 8, 8);
+        if (!image.isNull()) {
+            xcb_pixmap_t pm = qt_xcb_XPixmapFromBitmap(m_screen, image);
+            xcb_pixmap_t pmm = qt_xcb_XPixmapFromBitmap(m_screen, image.createAlphaMask());
+            cursor = xcb_generate_id(conn);
+            xcb_create_cursor(conn, cursor, pm, pmm, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 8, 8);
+        }
     }
 
     return cursor;