Sprite Kit iOS 7.1 crash on removeFromParent

I also crash with SKShapeNode when its parent remove from superview in iOS 7.1

My work around is set SKShapeNode property to nil before it remove from parent


You can call this method before you dealloc (or present new scene) the SKShapeNodes

- (void)cleanUpChildrenAndRemove:(SKNode*)node {
    for (SKNode *child in node.children) {
        [self cleanUpChildrenAndRemove:child];
    }
    [node removeFromParent];
}

I had the same problem but that solved it. My original question:

SKShapeNode producing crash sometimes on dealloc EXC_BAD_ACCESS


Not sure if my situation exactly mimics yours, but I was getting the same error (with the same stack trace) and realized that I had set up two classes that were each keeping the SKShapeNode object as properties. I'm pretty sure that when I called removeFromParent to remove object node in ClassA the object was deallocated. Then, in ClassB, I called self.node = aNewNode (keep in mind that the object that self.node pointed to had been deallocated), the auto-synthesized setter tried to de-allocate node for a second time.

I thought ARC was supposed to keep track of all this, but the bug is very sporadic so I'm honestly not 100% sure what's going on. I have an SKSpriteNode with the same pattern and I have never seen it causing this error. My fix right now has been to make the ClassB property weak, so it's not a problem if self.node has already been deallocated. Hope that helps!


It seems to only happen on iOS 7.1. Not sure if it is an Apple bug, but this seems to fix it:

- (void)removeFromParent
{
    [self.aShapeNode removeFromParent];
    self.aShapeNode = nil;

    [super removeFromParent];
}