SKShapeNode producing crash sometimes on dealloc EXC_BAD_ACCESS

前端 未结 2 1117
不知归路
不知归路 2021-01-24 18:07

In my main scene I create 4 walls with this method:

-(void)createFirstWalls{

    CGFloat maxY = CGRectGetMaxY(self.frame);
    Wall* wall1=[Wall wallWithRect:se         


        
相关标签:
2条回答
  • 2021-01-24 18:35

    One possible cause is that you aren't releasing the CGPathRef object. See this question/answer.

    Try adding these two lines after last using the path:

    self.path=path;
    
    CGPathRelease(path);
    path = nil;
    

    Also there used to be a bug where removing SKShapeNodes caused a crash. Be sure to run the latest Xcode 5 version / iOS 7.1 SDK.

    0 讨论(0)
  • 2021-01-24 18:46

    It seems to be a bug with the SKShapeNode in iOS 7.1 ...

    But finally I found the answer!!! Hope this can help more people.

    I implemented a method to remove all the childs in the current node

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

    And then call that function before I present a new scene

        [self cleanUpChildrenAndRemove:self]; //god bless this method
        SKScene* gameOver =[GameOver sceneWithSize:self.view.bounds.size];
        gameOver.scaleMode = SKSceneScaleModeAspectFill;
        [self.view presentScene:gameOver];
    

    No more crashes nor BAD_EXC... A true miracle.

    0 讨论(0)
提交回复
热议问题