2

I am new to SpriteKit and just built my first game. Everything was working great until iOS 7.1. Now, after a few times of advancing to a new level and presenting a new Scene, it crashes. I don't think I am presenting it in an incorrect way:

ZSSMyScene *nextLevel = [[ZSSMyScene alloc] initWithSize:self.size level:self.level score:score];
[self.view presentScene:nextLevel];

I get a EXC_BAD_ACCESS error, and it looks like it is happening on removeSubsprite, but I can't find anywhere in my code that I would be removing a subsprite:

enter image description here

Not sure what other info to provide as this is just an obscure error that seemed to start when I updated to iOS 7.1 SDK.

Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
  • 4
    Do you have SKShapeNode as children of other nodes (specifically SKSpriteNode)? If so, check if the crash goes away without the SKShapeNode children. I almost immediately get this crash when I enable physics or node shape debug drawing which adds shape nodes to many nodes. Seems to be a bug in iOS 7.1 version of Sprite Kit. – CodeSmile Mar 23 '14 at 21:05
  • @LearnCocos2D Yeah, I have a `SKSpriteNode` that I am adding as a child of the scene. I need to do this, so is there any way around this?! – Nic Hubbard Mar 24 '14 at 15:08
  • 1
    I believe this thread answers it: http://stackoverflow.com/questions/22399278/sprite-kit-ios-7-1-crash-on-removefromparent – Greg Mar 24 '14 at 17:27
  • So, in my `SKSpriteNode` subclass I need to override `removeFromParent`? I don't get what I am making nil though... – Nic Hubbard Mar 24 '14 at 21:26

1 Answers1

1

This appears to be a bug, possibly only with SKShapeNodes.

My solution was to create an SKNode category and call this cleanup method when any node i'm removing has children.

- (void)cleanUpChildrenAndRemove {
    for (SKNode *child in self.children) {
        [child cleanUpChildrenAndRemove];
    }
    [self removeFromParent];
}
ndomin
  • 428
  • 4
  • 11