I've been using my code successfully in OSX 10.14 to generate Metal textures:
let textureLoaderOptions = [MTKTextureLoader.Option.origin : MTKTextureLoader.Origin.bottomLeft, MTKTextureLoader.Option.textureStorageMode : MTLStorageMode.managed.rawValue] as [MTKTextureLoader.Option : Any]
do {
let _image = myNSImage.cgImage(forProposedRect: nil, context: nil, hints: nil)
let textureLoader = MTKTextureLoader(device: device)
texture = try textureLoader.newTexture(cgImage: _image, options: textureLoaderOptions)
} catch {
dump(error)
}
NB: Extra logic and error handling is omitted for brevity.
Now I've upgraded the build computer to 10.15, I get the following error caught:
Error Domain=MTKTextureLoaderErrorDomain Code=0 "Image decoding failed" UserInfo={NSLocalizedDescription=Image decoding failed, MTKTextureLoaderErrorKey=Image decoding failed}
I'm currently looking into using:
textureLoader.newTexture(URL: URL(fileURLWithPath: imageFilePath), options:textureLoaderOptions)
but owing to the other logic that surrounds the original code I'd much rather know if there isn't an incredibly easy thing that I've missed for the new OSX. I'm making the presumption that it definitely is connected to the OSX as absolutely nothing else - i.e. Xcode version or hardware - has changed. It worked yesterday and now it doesn't. I even submitted the working app to the App Store and it was rejected for this crash when they ran it in OSX 10.15.
The images that I'm using are png
and tiff
. Both with the same error and both worked in OSX 10.14.
So it seemed the upgrade opened a whole can of worms. The entire project needed to be rebuilt and this answer appears to fix my particular problem. As @0xBFE1A8 eluded to in their comments, the manner in which I produce a CGImage
from a NSImage
needed to be reworked after the upgrade.