SKShapeNode producing crash sometimes on dealloc EXC_BAD_ACCESS

前端 未结 2 1118
不知归路
不知归路 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: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.

提交回复
热议问题