I've just encountered an error I haven't been able to solve. I get a EXC_BAD_ACCESS (code=1, address=0x30) failure when my SpriteKit scene is loading up.
In viewWillAppear(...) my Game View Controller calls the loadGame(...) function:
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(....)
}
}
In my Game Scene, the load function stores the variables passed to it and then I load the game resources in a background thread:
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()
}
}
I get the error during the loadBoard(...) function essentially on the lines:
if let labelTexture = view?.textureFromNode(charNodeRefLabel!)
{
let convertedLabel = SKSpriteNode(texture: labelTexture)
convertedLabel.name = "labelTexture"
convertedLabel.zPosition = 1
pieceNode.addChild(convertedLabel)
}
View and the charNodeRefLabel are confirmed to be non-nil. charNodeRefLabel is a simple SKLabelNode. Also, I've tried placing the presentScene(...) call before and after the scene.load(...) but it still crashes the same way.
If I comment out the dispatch_async(...) then it doesn't crash but the UI becomes slow and unresponsive as it's loading quite a lot. I hadn't encountered this error until after I upgraded my project to Swift 1.2.
More puzzling is it doesn't always happen, and sometimes instead the EXC_BAD_ACCESS occurs on line:
class AppDelegate: UIResponder, UIApplicationDelegate
I'm really perplexed by this issue, could someone help me out and let me know if there's an obvious mistake? I've been trying to fix it for the past two days but haven't got anywhere.
Please let me know if I can provide any extra information to help.
Many thanks,
AppDelegate crash trace:
* 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
In case anyone else has this issue, it was solved (albeit unsatisfactorily) by simply using dispatch_async(...) on dispatch_get_main_queue(). The problem hasn't appeared yet since doing this.