UIImage(named:) with MTKTextureLoader throws error "Image decoding failed"

Number:rdar://31722523 Date Originated:2017-04-19
Status:Open Resolved:
Product:iOS + SDK Product Version:10.3.1
Classification: Reproducible:

The image that I tested with is a PNG with RGB + alpha channels which was stored in Assets.xcassets. The asset image is universal with 1x, 2x, 3x versions. It was retrieved using UIImage(named:).

Steps to Reproduce:
1. Set up a MTKTextureLoader
2. Get a PNG with alpha from assets using UIImage(named:)
3. Get the CGImage from the image
4. Attempt to load it using loader.newTexture(with:options:)
5. Get error "Image decoding failed"

Expected Results:
An MTLTexture object.

Actual Results:
Error "Image decoding failed"

iPhone 6s (MKRY2LL/A)


Could reproduce.

Reproduced on iPad Pro (Model A1670), XCode Version 9.2 (9C40b), iOS 11.2.1, Metal 2 Framework

Edit: There is a known workaround suggested by Apple after reporting this bug: "For the PNG image you are attempting to load, are the colors (regardless of their transparency) grey-scale or monochrome? If that’s the case, this is a known issue, for which a workaround is to store the image as a MTLTexture asset in Xcode (so that the image conversion is done at build-time rather than at runtime)."

By jonasjaszkowic at Jan. 1, 2018, 12:50 p.m. (reply...)

Can verify that this occurs.

Reproduced on iPhone 7, XCode Version 8.3.3 (8E3004b), iOS 10.3.2

By lambdasquirrel at July 9, 2017, 11:14 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!