0

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.

Todd
  • 1,770
  • 1
  • 17
  • 42
  • Have you tried compiling the same code using objective c? Does it produce the same error? – Hamid Yusifli Nov 01 '19 at 18:17
  • 1
    I could try a small test project. – Todd Nov 01 '19 at 18:19
  • @0xBFE1A8 thanks, but after a brief look it seems the code isn’t directly port-able to Obj-C. I’d have to create a texture and write the TiffRepresentation into it. If it did work then a direct Swift port of *that* code would probably work too, but I would like to find out what’s wrong with mine. – Todd Nov 01 '19 at 20:05
  • 1
    How do you load cgimage? – Hamid Yusifli Nov 01 '19 at 20:11
  • It comes from an NSImage that’s obtained from a security-scoped URL. I’ll have to try and think how best to put that in without providing the entire project! – Todd Nov 01 '19 at 20:18
  • This is beginning to look like a project issue: cut and paste code into a new project and there’s no problem. I’ve had this before and cut/pasting/dragging the same code into a new project made it work again :( – Todd Nov 01 '19 at 23:17

1 Answers1

0

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.

Todd
  • 1,770
  • 1
  • 17
  • 42