我正在 xCode for iPhone 中处理一个项目,我收到 EXC_BAD_ACCESS 错误,但是,我只在单步执行我尝试调试的函数时收到错误。当我从函数中取出断点,但仍以调试模式运行项目时,我从未收到此错误。无论如何要解决这个问题或找出导致 EXC_BAD_ACCESS 错误的原因。
错误来了:for ( BEUCharacterAIBehavior *behavior in behavior_.behaviors )
但是,当单步执行值时,behavior_.behaviors 会被分配和保留。NSZombiesEnabled 已设置,但仍会收到神秘的错误消息。
代码:
-(BEUCharacterAIBehavior *)getHighestValueBehaviorFromBehavior:(BEUCharacterAIBehavior *)behavior_ {
//if the behavior is a leaf then stop checking because there are no sub behaviors
if([behavior_ isLeaf]) return behavior_;
//temp variable for highest value behavior so far
BEUCharacterAIBehavior *highest = nil;
//NSLog(@"BEHAVIORS:%@",behavior_.behaviors);
for ( BEUCharacterAIBehavior *behavior in behavior_.behaviors )
{
//if there is a highest value behavior check if the highest value behavior has a larger value than the new one
if(highest)
{
if(highest.lastValue > behavior.value) continue;
}
//if there is no current behavior then the highest is now the behavior were checking because we have nothing to check against
if(!currentBehavior) highest = behavior;
//Make sure the current behavior is not the same behavior as the new one
else if(currentBehavior != behavior)
{
//can the new behaviors parent run multiple times in a row
if(!behavior.parent.canRunMultipleTimesInARow)
{
//make sure the current and new behaviors parents arent the same if they are continue to next behavior
if(currentBehavior.parent != behavior.parent)
{
continue;
}
}
highest = behavior;
//If current behavior and new behavior are the same make sure they can run multiple times
} else if(currentBehavior.canRunMultipleTimesInARow)
{
highest = currentBehavior;
}
}
//NSLog(@"GOING TO GET HIGHEST VALUE BEHAVIOR FROM BEHAVIOR: %d",highest.retainCount);
if(!highest) return nil;
return [self getHighestValueBehaviorFromBehavior:highest];//highest;
}
错误堆栈
0 0x02aebdcb 在 object_getClass
1 0x00002ac0 在
2 0x00014bb9 在 -[BEUCharacterAI getHighestValueBehaviorFromBehavior:] 在 BEUCharacterAI.m:115
3 0x00014b6b 在 -[BEUCharacterAI getHighestValueBehavior] 在 BEUCharacterAI.m:103
4 个字符 [0x0001AI4904 ] 在 BEUBEUacterAIm:104 68
5 0x00008975 in -[BEUCharacter step:] at BEUCharacter.m:229
6 0x00022aeb in -[EskimoCharacter step:] at EskimoCharacter.m:28
7 0x0000ed2b in -[BEUObjectController step:] at BEUObjectController.m:381
8 0x00003651 in - [BEUGame 步骤:] 在 BEUGame.m:63
9 0x0007cc42 在 -[CCTimer fire:] 在 CCScheduler.m:87
10 0x0007d846 在 -[CCScheduler tick:] 在 CCScheduler.m:212
11 0x000500b3 in -[CCDirector mainLoop] at CCDirector.m:208
12 0x000532b3 in -[CCDisplayLinkDirector preMainLoop:] at CCDirector.m:1055
13 0x00796f06 in CA::Display::DisplayLink::dispatch
14 0x0079704b in CA::Display: :EmulatorDisplayLink::callback
15 0x029810f3 in CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
16 0x02982734 in __CFRunLoopDoTimer
17 0x028df689 in __CFRunLoopRun
18 0x028dec00 in CFRunLoopRunSpecific
19 0x028deb21 in CFRunLoopRunInMode
20 0x03e96378 in GSEventRunModal
21 0x03e9643d in GSEventRun
22 0x0083bf89 in UIApplicationMain
23 0x00002b50 in main at main.m:13