Post

Replies

Boosts

Views

Activity

Cannot Load Texture with MTKTextureLoader
Every time I attempt to load an image using MTKTextureLoader, my app crashes simply saying "Image decoding failed". Here is the relevant code:let loader = MTKTextureLoader(device: Renderer.main.device) do { texture = try loader.newTexture(name: name, scaleFactor: Renderer.main.displayLayer.contentsScale, bundle: Bundle.main, options: nil) } catch(let error) { fatalError("Error when loading image \"\(name)\": " + error.localizedDescription) }(name = "Circle"; Circle is an image in my asset catalog)This is not an issue of not finding the image, because if I change the "name" variable to something that is not in my asset catalog, I get an error that states the image could not be located. This also does not have to do with the "scaleFactor", because I have tried manually setting that to 1.0, 2.0, and 3.0, with no success. I have checked the .png's properties using the file command, and it gives me this:PNG image data, 300 x 300, 8-bit/color RGBA, non-interlacedSo clearly the file is not corrupt and certainly is not unusual; it's just your average .png file. Also, this is erroring when run on my iPhone 8 (iOS 12.4; deployment target is iOS 10.3).Is there some step I'm missing or doing wrong?
6
0
3.5k
Aug ’19