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>
This commit is contained in:
parent
a962bbec07
commit
cd41b01f32
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user