Strange EXC_BAD_ACCESS SpriteKit removeSubsprite crash

不打扰是莪最后的温柔 提交于 2019-11-28 09:44:50

问题


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:

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.


回答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];
}


来源:https://stackoverflow.com/questions/22597014/strange-exc-bad-access-spritekit-removesubsprite-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!