我刚刚遇到一个我无法解决的错误。我的SpriteKit场景加载时,我得到一个EXC_BAD_ACCESS(代码= 1,地址= 0x30)失败。
在viewWillAppear(...)中,我的Game View Controller调用了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)
}
查看和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
答案 0 :(得分:1)
如果其他人有这个问题,只需在dispatch_get_main_queue()上使用dispatch_async(...)即可解决(尽管不能令人满意)。自从这样做以来,这个问题还没有出现。