So here's the block of code in question:
if let _ = UIImage(named: "\(storyCharacter.spriteBaseName)-\(status)") {
fileName = "\(storyCharacter.spriteBaseName)-\(status)"
} else {
// Try just the default image if one isn't found for the status
if let _ = UIImage(named: storyCharacter.spriteBaseName) {
fileName = storyCharacter.spriteBaseName
} else {
// Take the defaults out of the classes
if (storyCharacter.isGraphic == true) {
fileName = defaultGraphicImage
} else {
fileName = defaultCharacterImage
}
}
}
// Skin the sprite as appropriate
storyCharacter.currentSprite.texture = SKTexture(imageNamed: fileName) // Since it's been created and we're technically re-skinning it...
As you can see, I use UIImage to check to ensure that the image to be called for the texture exists without any question whatsoever, and if I fall back it checks the fallback before going to a known, set default image.
This code was working just fine on my devices until I started running on the simulator to test different screen sizes. Since doing that, one particular image seems to have started throwing it off and producing the error in the title when it hit the last line. I re-loaded it on my phone and it's now doing the same error there where it wasn't before. Haven't tried putting the rebuilt version on my iPad right now because I'm going to be demoing this for someone this afternoon and prefer to have one copy that's still working right.
Question is, how can it be coming up as nil in this circumstance? Digging around in the debugger, I did see the following in Thread 1, one level deeper than the offending function call:
0x1a497c230 <+464>: bl 0x1a497c598 ; closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in Swift._assertionFailure(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never
-> 0x1a497c234 <+468>: brk #0x1 // Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Thanks for any insights!