SceneKit: Why does animated model work in Preview, in iOS simulator, on Mac, but not on iPhone

I have a scene with an animated .dae model that loads and works in Preview, in the Xcode editor, in the iOS simulator, and in a Mac app, but the scene doesn't load on the actual iPhone. How can I find out what went wrong? All I get is "Fatal error: Unexpectedly found nil while unwrapping an Optional value"


All textures have power of 2 dimensions.

The scene is not very large.

Is there any way to get insight into specifically what went wrong?

Replies

No exceptions are thrown by the following code:

if let path = Bundle.path(forResource: "holding_idle",

ofType: "scn",

inDirectory: "art.scnassets") {

let characterSceneURL = URL(fileURLWithPath: path)

do {

let characterScene = try SCNScene(url: characterSceneURL,

options: [SCNSceneSource.LoadingOption.checkConsistency : true,

SCNSceneSource.LoadingOption.strictConformance : true])

characterNode = characterScene.rootNode.clone()

scene.rootNode.addChildNode(characterNode!)

} catch {

print(error)

}

}

The Swift fatal error is an abort, not an exception, so you can't catch it. When it happens, does you app stop in the debugger? (It should.) In Xcode 9.2, Xcode should show you the source line that caused the error. IAC, you can get that from the backtrace. What is that code line?


I'm a little unsure whether your code fragment represents code that doesn't crash, or code that crashes but doesn't throw an exception.


Anyway, the first thing to do is narrow down the abort to a line of code.