I have updated iPad Air to 7.1 and Xcode to 5.1. Xcode wanted to update my project to recommended settings, I agreed.
After that my game began crashing in a couple o
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
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];
}
I am also experiencing the crash. However, the solutions to override the removeFromParent method and setting the SKShapeNode to nil didn't work for me.
I did discover that my crash was the combination of:
Having a SKShapeNode (either a subclass OR a child of a SKNode)
Having a SKPhysicsNode attached to a node (attached to a parent SKNode OR the SKShapeNode).
Calling the method removeFromParent
The solution I ended up using was overriding the removeFromParent method in my SKShapeNode subclass with the following:
- (void)removeFromParent
{
if( self.physicsBody != nil )
{
self.physicsBody = nil;
}
[super removeFromParent];
}
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