Icon engines: don't paint on a null-pixmap

If the pixmap created is null (perhaps because the size is null), then
don't paint into it. It might crash as we might end up with an invalid
device context.

Task-number: QTBUG-127085
Pick-to: 6.7
Change-Id: I03b3beabe02f150a2970013c15842369d3a27596
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit b2b4bc2f2fb5de53e262c88023f278f782b80de5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2024-07-31 16:22:01 +02:00 committed by Qt Cherry-pick Bot
parent fbbcd87039
commit 4fe0e5dbc4
3 changed files with 13 additions and 7 deletions

View File

@ -408,9 +408,11 @@ QPixmap QAppleIconEngine::scaledPixmap(const QSize &size, QIcon::Mode mode, QIco
m_pixmap.setDevicePixelRatio(scale);
m_pixmap.fill(Qt::transparent);
QPainter painter(&m_pixmap);
paint(&painter, QRect(paintOffset.width(), paintOffset.height(),
paintSize.width(), paintSize.height()), mode, state);
if (!m_pixmap.isNull()) {
QPainter painter(&m_pixmap);
paint(&painter, QRect(paintOffset.width(), paintOffset.height(),
paintSize.width(), paintSize.height()), mode, state);
}
m_cacheKey = cacheKey;
}

View File

@ -572,8 +572,10 @@ QPixmap QAndroidPlatformIconEngine::scaledPixmap(const QSize &size, QIcon::Mode
m_pixmap.fill(Qt::transparent);
m_pixmap.setDevicePixelRatio(scale);
QPainter painter(&m_pixmap);
paint(&painter, QRect(QPoint(), size), mode, state);
if (!m_pixmap.isNull()) {
QPainter painter(&m_pixmap);
paint(&painter, QRect(QPoint(), size), mode, state);
}
m_cacheKey = cacheKey;
}

View File

@ -353,8 +353,10 @@ QPixmap QWindowsIconEngine::scaledPixmap(const QSize &size, QIcon::Mode mode, QI
m_pixmap.fill(Qt::transparent);
m_pixmap.setDevicePixelRatio(scale);
QPainter painter(&m_pixmap);
paint(&painter, QRect(QPoint(), size), mode, state);
if (!m_pixmap.isNull()) {
QPainter painter(&m_pixmap);
paint(&painter, QRect(QPoint(), size), mode, state);
}
m_cacheKey = cacheKey;
}