I noticed a weird behavior in my Swift project and reproduced it on a empty SpriteKit Project that way:
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
let sprite = SKSpriteNode(imageNamed:"Spaceship")
self.addChild(sprite)
//sprite.removeFromParent()
let sprite2 = SKSpriteNode(imageNamed:"Spaceship")
self.addChild(sprite2)
sprite2.removeFromParent()
}
}
It crash before the app start and all I can see is this :

My config is xCode6-Beta6, iPad Mini Retina with iOS8-Beta5 and OSX 10.9.4.
I also reproduced the bug in the simulators; with xCode6-Beta5; and moving the code in touchesBegan method
Uncommenting the line sprite.removeFromParent() make the bug disappear.
IMPORTANT: this bug has been corrected since iOS 8.1, be sure to update AND make your app unavailable for iOS 8.0 and prior.
I found out what happens... and it should be some Apple employe which did a mistake. Explainations :
let sprite = SKSpriteNode(imageNamed:"Spaceship")
self.addChild(sprite)
let sprite2 = SKSpriteNode(imageNamed:"Spaceship")
self.addChild(sprite2)
sprite2.removeFromParent()
println( sprite == sprite2 ) // Returns "true"
// Then crash
And if you do it :
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.name = "1"
self.addChild(sprite)
let sprite2 = SKSpriteNode(imageNamed:"Spaceship")
sprite2.name = "2"
self.addChild(sprite2)
sprite2.removeFromParent()
println( sprite == sprite2 ) // Returns "false"
// Then all is right, no crash
I think very simply when you call .removeFromParent() Apple's code check for equality in code with == like they would do in Objective-C. But since it's Swift you should do === to check for object equality rather than ==, so a dumb mistake.
Congratz you found a bug in SpriteKit Code, go fill a form at Apple :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With