From b280182053a8ccd912eb165b59928e88a6d62c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Tue, 29 Oct 2013 15:06:34 +0100 Subject: [PATCH] Android: Don't rely on QIcon::isNull() to validate icon data. QIcon::isNull() only checks if it has a valid d pointer and not if it actually contains any image data. The result is that the QImage create from the icon would be invalid, and later cause an exception to be thrown. To avoid this we should check the QImage as well. Task-number: QTBUG-34416 Change-Id: I9dd0a2387d73bfc2c27ceb9df247ddc186dd659f Reviewed-by: BogDan Vatra --- src/plugins/platforms/android/src/androidjnimenu.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/android/src/androidjnimenu.cpp b/src/plugins/platforms/android/src/androidjnimenu.cpp index bb180347c1c..8964995832b 100644 --- a/src/plugins/platforms/android/src/androidjnimenu.cpp +++ b/src/plugins/platforms/android/src/androidjnimenu.cpp @@ -197,16 +197,18 @@ namespace QtAndroidMenu env->CallObjectMethod(menuItem, setCheckedMenuItemMethodID, checked); env->CallObjectMethod(menuItem, setEnabledMenuItemMethodID, enabled); - if (!icon.isNull()) { + if (!icon.isNull()) { // isNull() only checks the d pointer, not the actual image data. int sz = qMax(36, qgetenv("QT_ANDROID_APP_ICON_SIZE").toInt()); QImage img = icon.pixmap(QSize(sz,sz), enabled ? QIcon::Normal : QIcon::Disabled, QIcon::On).toImage(); - env->CallObjectMethod(menuItem, - setIconMenuItemMethodID, - createBitmapDrawable(createBitmap(img, env), env)); + if (!img.isNull()) { // Make sure we have a valid image. + env->CallObjectMethod(menuItem, + setIconMenuItemMethodID, + createBitmapDrawable(createBitmap(img, env), env)); + } } env->CallObjectMethod(menuItem, setVisibleMenuItemMethodID, visible);