按下Homebutton会导致SpriteKit SKView中的EXC_BAD_ACCESS代码= 1

当您按主页button时,SpriteKit应该清除并暂停所有定时器。

但是,我们发现,如果您在显示活动的SKView时单击主页button,应用程序将崩溃。 即使该视图已被用户暂停,也会发生这种情况。

奇怪的是,如果你双击主页button,移动到多任务视图,一切工作正常。

跟进注意:模拟器在两种情况下都能正常工作,不会发生崩溃

其他人是否看到SpriteKit的这个问题?

你find了原因/解决scheme?

我遇到了同样的问题,我手动解决它在应用程序移动到后台之前暂停ViewController中的根SKView:

- (void)viewDidLoad { [super viewDidLoad]; // Configure the view (already setup as SKView via storyboard) SKView * skView = (SKView *)self.view; // Create and configure the scene. SKScene *scene = [Menu sceneWithSize:CGSizeMake(skView.bounds.size.height, skView.bounds.size.width)]; scene.scaleMode = SKSceneScaleModeAspectFill; // Present the scene. [skView presentScene:scene]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterBackground) name:UIApplicationWillResignActiveNotification object:NULL]; } - (void)appWillEnterBackground { SKView *skView = (SKView *)self.view; skView.paused = YES; [[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:NULL]; } - (void)appWillEnterForeground { SKView * skView = (SKView *)self.view; skView.paused = NO; [[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterBackground) name:UIApplicationWillResignActiveNotification object:NULL]; } 
  1. 运行Xcode的分析器(Project> Analyze)来确定你的代码是否有内存pipe理问题。

  2. 在Instruments应用程序(Project> Profile)的分配工具中运行这个场景,它可以报告任何检测到的内存滥用情况。

我们遇到了与UICollectionView类似的不一致的行为。 在这种情况下,通过Storyboard实例化对象(与编程相对)解决了这个问题。

在一个预感上,我今天早上和维奥拉试过了,成功了!

所以,看起来故事板在SKView上做了一些神奇的事情,这些是我们所不知道的,并允许它们在Home Button按下时被正确终止。 令人沮丧,但至less现在起作用了。

这个问题可能是audio引起的,如果是这样你可以在这里查看答案https://stackoverflow.com/a/19283721/1278463

我在一个不使用audio的游戏中解决了这个问题。 解决scheme是在进入后台时暂停SKView:

 - (void)applicationDidEnterBackground:(UIApplication *)application { SKView *view = (SKView *)self.window.rootViewController.view; if (view) { view.paused = YES; } } - (void)applicationWillEnterForeground:(UIApplication *)application { SKView *view = (SKView *)self.window.rootViewController.view; if (view) { view.paused = NO; } }