Read all of the posts regarding this error being memory related and trying to access something that is no longer there.
Problem: Error pops up at virtually random intervals. It can appear after the first enemy is killed or the Nth enemy is killed. However, it ONLY appears when an enemy is killed.
Testing: Running iOS 8 beta 5, Xcode 6 beta 5 on iPhone 5s.
Code flow:
Enemy SKNodes class instances are created at start of level and stored in NSMutableArray for reference:
Goblin *newGoblin = [[Goblin alloc] initFacingDirection:1];
// set various properties…
[enemyGoblins addObject:newGoblin];
Player’s sword makes contact with enemy:
NSMutableArray *discardedItems = [NSMutableArray array];
for(Goblin *object in enemyGoblins)
{
[object runBloodBurst:true damagePoints:_player.swordDamage];
if(object.goblinHealth < 0)
[discardedItems addObject:object];
}
if([discardedItems count] > 0)
[enemyGoblins removeObjectsInArray:discardedItems];
In the Goblin class, the “die” code is:
if(self.goblinHealth < 0)
{
SKAction *wait0 = [SKAction waitForDuration:1.0];
SKAction *block0 = [SKAction runBlock:^{
[self removeActionForKey:@"animation"];
[self runAction:[_animations goblin_dieLeft]];
}];
SKAction *block1 = [SKAction runBlock:^{
[self removeFromParent];
}];
[self runAction:[SKAction sequence:@[block0, wait0, block1]]];
}
What I’ve tried: I disabled the “discardedItems” code because I thought ARC might dump the object from memory once the reference was lost and the subsequent Goblin class’ “die animation” would cause the crash but this did not resolve the issue. I tried zombies and breakpoints but got no useful clues either.
Am I barking up the wrong tree in regards to what I’ve tried or has anyone experienced a similar issue in Beta 5?
EDIT
Here is the backtrace:
(lldb) bt * thread #1: tid = 0x3264b, 0x000000018cb13434 SpriteKit
SKCSprite::update(double) + 404, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x7000000000000018) frame #0: 0x000000018cb13434 SpriteKit
SKCSprite::update(double) + 404 frame #1: 0x000000018cb13440 SpriteKitSKCSprite::update(double) + 416 frame #2: 0x000000018cb13440 SpriteKit
SKCSprite::update(double) + 416 frame #3: 0x000000018cacbf28 SpriteKit-[SKScene _update:] + 140 frame #4: 0x000000018cae63f8 SpriteKit
-[SKView(Private) _update:] + 568 frame #5: 0x000000018cae3a10 SpriteKit-[SKView renderCallback:] + 764 frame #6: 0x000000018cae0a9c SpriteKit
__29-[SKView setUpRenderCallback]_block_invoke + 60 frame #7: 0x000000018cb0d890 SpriteKit-[SKDisplayLink _callbackForNextFrame:] + 272 frame #8: 0x000000010042ca9c libglInterpose.dylib
-[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 168 frame #9: 0x000000018c615b90 QuartzCoreCA::Display::DisplayLinkItem::dispatch() + 32 frame #10: 0x000000018c615a28 QuartzCore
CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 324 frame #11: 0x00000001897dddc0 IOKitIODispatchCalloutFromCFMessage + 376 frame #12: 0x00000001885dcf34 CoreFoundation
__CFMachPortPerform + 180 frame #13: 0x00000001885f1b38 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56 frame #14: 0x00000001885f1a98 CoreFoundation
__CFRunLoopDoSource1 + 436 frame #15: 0x00000001885efa18 CoreFoundation__CFRunLoopRun + 1640 frame #16: 0x000000018851d664 CoreFoundation
CFRunLoopRunSpecific + 396 frame #17: 0x000000019154f5a4 GraphicsServicesGSEventRunModal + 168 frame #18: 0x000000018ccd6164 UIKit
UIApplicationMain + 1488 * frame #19: 0x0000000100165530 CarcerQuestmain(argc=1, argv=0x000000016fdab9d8) + 116 at main.m:16 frame #20: 0x000000019885aa08 libdyld.dylib
start + 4 (lldb)