diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-04-17 17:04:33 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-04-17 18:19:01 +0200 |
commit | cd41b01f32104a484db53e8a1ea913d596c939c7 (patch) | |
tree | 1304b2c6f622dba31644a3daa454c60624fc7888 /src/gui/painting/qcoregraphics.mm | |
parent | a962bbec0789f05ba6f1ea50c8656eeb5ac3ab00 (diff) |
macOS: Don't produce NSImages without a single representation
Doing so results in exceptions inside AppKit when passed on to APIs that
expect valid images. It's better to produce nil-images.
Fixes: QTBUG-83494
Change-Id: I1e5bfa2a7fecd75a1ddb95bd1a6dc2e8db6b24f8
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/painting/qcoregraphics.mm')
-rw-r--r-- | src/gui/painting/qcoregraphics.mm | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/gui/painting/qcoregraphics.mm b/src/gui/painting/qcoregraphics.mm index 94ba004c93..7fb075d19e 100644 --- a/src/gui/painting/qcoregraphics.mm +++ b/src/gui/painting/qcoregraphics.mm @@ -162,12 +162,12 @@ QT_END_NAMESPACE if (icon.isNull()) return nil; - auto nsImage = [[NSImage alloc] initWithSize:NSZeroSize]; - auto availableSizes = icon.availableSizes(); if (availableSizes.isEmpty() && size > 0) availableSizes << QSize(size, size); + auto nsImage = [[[NSImage alloc] initWithSize:NSZeroSize] autorelease]; + for (QSize size : qAsConst(availableSizes)) { QImage image = icon.pixmap(size).toImage(); if (image.isNull()) @@ -182,12 +182,15 @@ QT_END_NAMESPACE [nsImage addRepresentation:[imageRep autorelease]]; } + if (!nsImage.representations.count) + return nil; + [nsImage setTemplate:icon.isMask()]; if (size) nsImage.size = CGSizeMake(size, size); - return [nsImage autorelease]; + return nsImage; } @end |