我刚刚遇到了一个我无法解决的错误。当我的 SpriteKit 场景加载时,出现 EXC_BAD_ACCESS (code=1, address=0x30) 失败。
在 viewWillAppear(...) 我的游戏视图控制器调用 loadGame(...) 函数:
private func loadGame()
{
let gameSceneFile = getRelevantGameScene()
skView.ignoresSiblingOrder = true
if (skView.scene == nil)
{
scene = GameScene.unarchiveFromFile(gameSceneFile) as! GameScene
scene.scaleMode = .AspectFit
skView.presentScene(scene)
scene.load(....)
}
}
在我的游戏场景中,加载函数存储传递给它的变量,然后我在后台线程中加载游戏资源:
override func didMoveToView(view: SKView)
{
let backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
dispatch_async(backgroundQueue)
{
self.loadPauseMenu()
self.loadCompleteMenu()
self.loadBoard(self.boardSize)
self.play()
}
}
我在 loadBoard(...) 函数期间收到错误,基本上是:
if let labelTexture = view?.textureFromNode(charNodeRefLabel!)
{
let convertedLabel = SKSpriteNode(texture: labelTexture)
convertedLabel.name = "labelTexture"
convertedLabel.zPosition = 1
pieceNode.addChild(convertedLabel)
}
View 和 charNodeRefLabel 被确认为非零。charNodeRefLabel 是一个简单的 SKLabelNode。另外,我尝试在 scene.load(...) 之前和之后放置 presentScene(...) 调用,但它仍然以相同的方式崩溃。
如果我将 dispatch_async(...) 注释掉,那么它不会崩溃,但 UI 会变得缓慢且无响应,因为它加载了很多。直到我将项目升级到 Swift 1.2 之后,我才遇到这个错误。
更令人费解的是它并不总是发生,有时反而会在线发生 EXC_BAD_ACCESS:
class AppDelegate: UIResponder, UIApplicationDelegate
我真的对这个问题感到困惑,有人可以帮助我并让我知道是否有明显的错误吗?过去两天我一直在尝试修复它,但没有任何地方。
如果我可以提供任何额外的信息来帮助,请告诉我。
非常感谢,
AppDelegate 崩溃跟踪:
* thread #1: tid = 0xcc0d2, 0x000000018ee965cc IOAccelerator`IOAccelResourceGetDataSize, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x28)
frame #0: 0x000000018ee965cc IOAccelerator`IOAccelResourceGetDataSize
frame #1: 0x000000018e06ef88 libGPUSupportMercury.dylib`gpusSubmitDataBuffers + 244
frame #2: 0x0000000188e111f4 GLEngine`gliPresentViewES_Exec + 196
frame #3: 0x0000000188e110f8 GLEngine`gliPresentViewES + 84
frame #4: 0x0000000188e1fc58 OpenGLES`-[EAGLContext presentRenderbuffer:] + 72
frame #5: 0x00000001004b5200 libglInterpose.dylib`EAGLContext_presentRenderbuffer(EAGLContext*, objc_selector*, unsigned long) + 372
frame #6: 0x0000000189967620 SpriteKit`-[SKView renderContent] + 228
frame #7: 0x00000001899644f8 SpriteKit`__29-[SKView setUpRenderCallback]_block_invoke + 64
frame #8: 0x00000001899906e8 SpriteKit`-[SKDisplayLink _callbackForNextFrame:] + 272
frame #9: 0x00000001004b47fc libglInterpose.dylib`-[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 168
frame #10: 0x000000018948a29c QuartzCore`CA::Display::DisplayLinkItem::dispatch() + 32
frame #11: 0x000000018948a134 QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 324
frame #12: 0x0000000186265470 IOKit`IODispatchCalloutFromCFMessage + 376
frame #13: 0x0000000185056dc4 CoreFoundation`__CFMachPortPerform + 180
frame #14: 0x000000018506ba54 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
frame #15: 0x000000018506b9b4 CoreFoundation`__CFRunLoopDoSource1 + 436
frame #16: 0x0000000185069934 CoreFoundation`__CFRunLoopRun + 1640
frame #17: 0x0000000184f952d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #18: 0x000000018e7b36fc GraphicsServices`GSEventRunModal + 168
frame #19: 0x0000000189b5afac UIKit`UIApplicationMain + 1488
* frame #20: 0x0000000100102c04 WS`main + 164 at AppDelegate.swift:12
frame #21: 0x0000000196f06a08 libdyld.dylib`start + 4