Search code examples
sprite-kitexc-bad-accessdeallocskshapenode

SKShapeNode dealloc EXC_BAD_ACCESS


I'm having some strange problems with sprite kit throwing up when trying to destroy an SKShapeNode. The image below is an extract from the stack trace.

Has anyone seen this before? I don't seem to get this problem when using SKSpriteNodes (i.e., when BAJoint isa SKSpriteNode rather than an SKShapeNode.

enter image description here

In addition, if you look at the stack trace you will see a call to SKEffectNode's dealloc. I have not used SKEffectNodes anywhere in my application in any shape or form, so I'm puzzled why the SKEffectNode dealloc is being invoked.


Solution

  • Had the same problem, but finally I've solved it. I left you the link here

    SKShapeNode producing crash sometimes on dealloc EXC_BAD_ACCESS

    The solution was to call this method before dealloc the shapes (in my case, before I present a new scene)

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