进入背景时,Spritekit崩溃 [英] Spritekit crashes when entering background

查看:778
本文介绍了进入背景时,Spritekit崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我一直在开发一个应用程序,其中我有一个NSMutableDictionary与SKAction对象。
SKAction用于播放声音。



这一切都很好,除了...应用程序崩溃时输入背景与以下堆栈跟踪: p>

  * thread#1:tid = 0x187d7,0x3461b932 libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient + 10,queue ='com.apple.spritekit.renderQueue ,stop reason = EXC_BAD_ACCESS(code = 1,address = 0x1)
frame#0:0x3461b932 libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient + 10
frame#1:0x3461c3d0 libGPUSupportMercury.dylib`gpusSubmitDataBuffers + 104
frame#2:0x2eafc4a4 IMGSGX554GLDriver`SubmitPackets + 124
frame#3:0x31f83cb0 GLEngine`gliPresentViewES + 168
frame#4:0x31f8e136 OpenGLES`- [EAGLContext presentRenderbuffer:] + 62
frame#5 :0x002622e6 libglInterpose.dylib`EAGLContext_presentRenderbuffer(EAGLContext *,objc_selector *,unsigned int)+ 370
frame#6:0x323f9064 SpriteKit`- [SKView _renderContent] + 1220
frame#7:0x3a90b0ae libdispatch.dylib` _dispatch_client_callout + 22
frame#8:0x3a90f8f2 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 26
frame#9:0x323f8b72 SpriteKit`- [SKView renderContent] + 82
frame#10:0x323f651a SpriteKit` [SKView setUpRenderCallback] _block_invoke + 130
frame#11:0x32418c86 SpriteKit`- [SKDisplayLink _callbackForNextFrame:] + 254
frame#12:0x002615fe libglInterpose.dylib`- [DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 270
frame#13:0x321d7ad2 QuartzCore`CA :: Display :: DisplayLinkItem :: dispatch()+ 98
frame#14:0x321d787c QuartzCore`CA :: Display :: DisplayLink :: dispatch_items(unsigned long long,unsigned long long,unsigned long long)+ 344
frame#15:0x34dd476c IOMobileFramebuffer`IOMobileFramebufferVsyncNotifyFunc + 104
frame#16:0x30a5ebe4 IOKit`IODispatchCalloutFromCFMessage + 248
frame#17:0x2fd3cb80 CoreFoundation`__CFMachPortPerform + 136
frame#18:0x2fd47776 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame#19:0x2fd47712 CoreFoundation`__CFRunLoopDoSource1 + 346
frame#20:0x2fd45ede CoreFoundation`__CFRunLoopRun + 1406
frame#21: 0x2fcb0470 CoreFoundation`CFRunLoopRunSpecific + 524
frame#22:0x2fcb0252 CoreFoundation`CFRunLoopRunInMode + 106
frame#23:0x349b72ea GraphicsServices`GSEventRunModal + 138
frame#24:0x32565844 UIKit`UIApplicationMain + 1136
frame#25:0x000bd1bc SpritekitCrash`main(argc = 1,argv = 0x27d4dc5c)+ 116在main.m:16


b $ b

因为它说EXC_BAD_ACCESS,我怀疑僵尸对象,但启用他们在方案中没有帮助一个事情了解这个崩溃。



甚至发生在MyScene.m中最简约的项目设置(实际上是两行代码):

  self.arrSounds = [[ NSMutableDictionary alloc] init]; 
[self.arrSounds setObject:[SKAction playSoundFileNamed:[NSString stringWithFormat:@70.caf] waitForCompletion:NO] forKey:[NSString stringWithFormat:@1]];

如何实现?



可以从我的github页面下载此项目: https://github.com/SabatinoMasala/SpritekitCrash



在后台,Spritekit使用 AVAudioSession (有意义)[SKAction playSoundFileNamed:]



AVAudioSession不能在应用程序处于后台时处于活动状态,所以我们必须在进入时停止



在applicationWillResignActive和applicationDidEnterBackground中使用这段代码来禁用AVAudioSession:

  [[AVAudioSession sharedInstance] setActive:NO er​​ror:nil]; 

要再次启用它,请在applicationWillEnterForeground中使用:

  [[AVAudioSession sharedInstance] setActive:YES error:nil]; 


Allright guys, I've been developing an app in which I have a NSMutableDictionary with an SKAction object in it. The SKAction is for playing a sound.

This all works well, except ... the app crashes upon entering background with the following stack trace:

* thread #1: tid = 0x187d7, 0x3461b932 libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient + 10, queue = 'com.apple.spritekit.renderQueue, stop reason = EXC_BAD_ACCESS (code=1, address=0x1)
frame #0: 0x3461b932 libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient + 10
frame #1: 0x3461c3d0 libGPUSupportMercury.dylib`gpusSubmitDataBuffers + 104
frame #2: 0x2eafc4a4 IMGSGX554GLDriver`SubmitPackets + 124
frame #3: 0x31f83cb0 GLEngine`gliPresentViewES + 168
frame #4: 0x31f8e136 OpenGLES`-[EAGLContext presentRenderbuffer:] + 62
frame #5: 0x002622e6 libglInterpose.dylib`EAGLContext_presentRenderbuffer(EAGLContext*, objc_selector*, unsigned int) + 370
frame #6: 0x323f9064 SpriteKit`-[SKView _renderContent] + 1220
frame #7: 0x3a90b0ae libdispatch.dylib`_dispatch_client_callout + 22
frame #8: 0x3a90f8f2 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 26
frame #9: 0x323f8b72 SpriteKit`-[SKView renderContent] + 82
frame #10: 0x323f651a SpriteKit`__29-[SKView setUpRenderCallback]_block_invoke + 130
frame #11: 0x32418c86 SpriteKit`-[SKDisplayLink _callbackForNextFrame:] + 254
frame #12: 0x002615fe libglInterpose.dylib`-[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 270
frame #13: 0x321d7ad2 QuartzCore`CA::Display::DisplayLinkItem::dispatch() + 98
frame #14: 0x321d787c QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 344
frame #15: 0x34dd476c IOMobileFramebuffer`IOMobileFramebufferVsyncNotifyFunc + 104
frame #16: 0x30a5ebe4 IOKit`IODispatchCalloutFromCFMessage + 248
frame #17: 0x2fd3cb80 CoreFoundation`__CFMachPortPerform + 136
frame #18: 0x2fd47776 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #19: 0x2fd47712 CoreFoundation`__CFRunLoopDoSource1 + 346
frame #20: 0x2fd45ede CoreFoundation`__CFRunLoopRun + 1406
frame #21: 0x2fcb0470 CoreFoundation`CFRunLoopRunSpecific + 524
frame #22: 0x2fcb0252 CoreFoundation`CFRunLoopRunInMode + 106
frame #23: 0x349b72ea GraphicsServices`GSEventRunModal + 138
frame #24: 0x32565844 UIKit`UIApplicationMain + 1136
frame #25: 0x000bd1bc SpritekitCrash`main(argc=1, argv=0x27d4dc5c) + 116 at main.m:16

Since it said EXC_BAD_ACCESS, I suspected zombie-objects, but enabling them in the scheme didn't help a thing in understanding this crash.

This even happens in the most minimalistic project setup (literally 2 lines of code) in MyScene.m:

self.arrSounds = [[NSMutableDictionary alloc] init];
[self.arrSounds setObject:[SKAction playSoundFileNamed:[NSString stringWithFormat:@"70.caf"] waitForCompletion:NO] forKey:[NSString stringWithFormat:@"1"]];

How is this possible?

You can download this project from my github page: https://github.com/SabatinoMasala/SpritekitCrash

解决方案

Allright, I found the issue.

Behind the scenes, Spritekit uses AVAudioSession (which makes sense) for [SKAction playSoundFileNamed:]

AVAudioSession cannot be active while the application is in the background, so we have to stop it when going in to background, and reactivate it when entering foreground.

Use this piece of code in both applicationWillResignActive and applicationDidEnterBackground to disable the AVAudioSession:

[[AVAudioSession sharedInstance] setActive:NO error:nil];

To enable it again, use this in applicationWillEnterForeground:

[[AVAudioSession sharedInstance] setActive:YES error:nil];

这篇关于进入背景时,Spritekit崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆