Cocoa: add qWarnining when trying to create 0 width/height CGImages
authorTeemu Katajisto <teemu.katajisto@digia.com>
Fri, 5 Oct 2012 10:48:43 +0000 (13:48 +0300)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 8 Oct 2012 06:51:09 +0000 (08:51 +0200)
Add meaningful warnings when trying to create 0 width/height CGImages.
This way it is easier to track down the place where valid size is not
used.

Change-Id: Id261ddf72d5487afcdb1a2a6d0d9079700888545
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/plugins/platforms/cocoa/qcocoahelpers.mm
src/plugins/platforms/cocoa/qnsview.mm
src/plugins/platforms/cocoa/qpaintengine_mac.mm

index d950878..8841a65 100644 (file)
@@ -79,6 +79,12 @@ static void drawImageReleaseData (void *info, const void *, size_t)
 
 CGImageRef qt_mac_image_to_cgimage(const QImage &img)
 {
+    if (img.width() <= 0 || img.height() <= 0) {
+        qWarning() << Q_FUNC_INFO <<
+            "trying to set" << img.width() << "x" << img.height() << "size for CGImage";
+        return 0;
+    }
+
     QImage *image;
     if (img.depth() != 32)
         image = new QImage(img.convertToFormat(QImage::Format_ARGB32_Premultiplied));
index 3352762..a95ff45 100644 (file)
@@ -192,12 +192,20 @@ static QTouchDevice *touchDevice = 0;
 {
     CGImageRelease(m_cgImage);
 
+    int width = image->width();
+    int height = image->height();
+
+    if (width <= 0 || height <= 0) {
+        qWarning() << Q_FUNC_INFO <<
+            "setting invalid size" << width << "x" << height << "for qnsview image";
+        m_cgImage = 0;
+        return;
+    }
+
     const uchar *imageData = image->bits();
     int bitDepth = image->depth();
     int colorBufferSize = 8;
     int bytesPrLine = image->bytesPerLine();
-    int width = image->width();
-    int height = image->height();
 
     CGColorSpaceRef cgColourSpaceRef = CGColorSpaceCreateDeviceRGB();
 
index e6877e6..8c47527 100644 (file)
@@ -1022,7 +1022,8 @@ void QCoreGraphicsPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, co
         image = qt_mac_create_imagemask(pm, sr);
     } else if (differentSize) {
         QCFType<CGImageRef> img = qt_mac_image_to_cgimage(pm.toImage());
-        image = CGImageCreateWithImageInRect(img, CGRectMake(qRound(sr.x()), qRound(sr.y()), qRound(sr.width()), qRound(sr.height())));
+        if (img)
+            image = CGImageCreateWithImageInRect(img, CGRectMake(qRound(sr.x()), qRound(sr.y()), qRound(sr.width()), qRound(sr.height())));
     } else {
         image = qt_mac_image_to_cgimage(pm.toImage());
     }