使用dispatch_block_t时EXC_BAD_ACCESS

时间:2016-03-04 20:51:00

标签: ios objective-c sprite-kit

我有一个游戏菜单,介绍场景和游戏本身。如果玩家死了,我想再次显示游戏菜单。当游戏开始菜单出现时。按新游戏显示介绍场景应该如此。经过一段时间的动画后,会触发self.sceneEndCallback()并显示游戏场景。当玩家死亡时,self.gameEndCallback()与EXC_BAD_ACCESS崩溃。

GameViewController.m

        __weak GameViewController *weakSelf = self;
        IntroScene *introScene = [IntroScene nodeWithFileNamed:@"IntroScene"];
        introScene.scaleMode = SKSceneScaleModeAspectFill;
        [skView presentScene:introScene];
        introScene.sceneEndCallback = ^{
            GameScene *scene = [GameScene nodeWithFileNamed:@"GameScene"];
            scene.scaleMode = SKSceneScaleModeAspectFill;
            SKTransition *transition = [SKTransition fadeWithDuration:2];
            [skView presentScene:scene transition:transition];
            scene.gameEndCallback = ^{
                [weakSelf.navigationController popViewControllerAnimated:YES];
            };

        };

GameScene.h

@property (nonatomic, copy) dispatch_block_t gameEndCallback;

1 个答案:

答案 0 :(得分:0)

是否真的在调用introScene.sceneEndCallback?因为,如果没有这个,scene.gameEndCallback将为NULL并且尝试调用它将因BAD_ACCESS而崩溃。