I am working on a project in xCode for iPhone where I am receiving an EXC_BAD_ACCESS error, HOWEVER, I only receive the error when stepping through a function I am trying to debug. When I take my breakpoint off the function, but still run the project in Debug Mode, I never receive this error. Is there anyway to solve this or find out what is causing the EXC_BAD_ACCESS error.
The error comes on the line: for ( BEUCharacterAIBehavior *behavior in behavior_.behaviors )
However when stepping through the value behavior_.behaviors is allocated and retained. NSZombiesEnabled is set but still get the cryptic error message.
Code:
-(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;
}
Error stack
0 0x02aebdcb in object_getClass
1 0x00002ac0 in 2 0x00014bb9 in -[BEUCharacterAI getHighestValueBehaviorFromBehavior:] at BEUCharacterAI.m:115 3 0x00014b6b in -[BEUCharacterAI getHighestValueBehavior] at BEUCharacterAI.m:103 4 0x00014904 in -[BEUCharacterAI update:] at BEUCharacterAI.m: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 step:] at BEUGame.m:63 9 0x0007cc42 in -[CCTimer fire:] at CCScheduler.m:87 10 0x0007d846 in -[CCScheduler tick:] at 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:13I was having this with Xcode 4.2.1 and lldb. Switching to gdb solved the problem.
It's not immediately clear to me what your problem is, but this document might help:
Mac OS X Debugging Magic
Do you have other threads running? It could be that something else is modifying behavior_.behaviors or simply behavior_ while your loop is running, but the window is quite small unless the loop is running really slowly. You could try putting a long sleep in the loop to simulate debugging and see if that makes the crash happen when running outside the debugger.
I have seen this as well under XCode 4 running unit tests in the simulator. At this point I'm chalking it up to a bug in the iOS Simulator somewhere.
I'll edit this answer if I discover more.
I, too, get this behavior when using the debugger in Xcode 4. I place breakpoints in my code, in my classes which are subclasses of SenTestCase. I run via Product -> Test in Xcode.
I consistently get the error on this statement:
Node *newEntry = [[Node alloc] initWithPayload:payload];
I only post that code in case anyone is experiencing it on an -alloc or -init....
When I run Product -> Test after removing all breakpoints, the code runs just fine (including the above line called repeatedly) and the tests all complete successfully.
Just FYI in case anyone is experiencing the same.
I get the error on every line I put my Breakpoint on.
Even on
NSError *error = nil;
EXC_BAD_ACCESS !
Debugger without breakpoints runs smoothly. On Simulator and Device, runs without problems. Without Debugger also no Problem. I am using LLVM LDB 3.0.
NOW I swtiched to GDB in my Scheme under "Run" and it works like a charm.
Hopefully they will fix this, or eventually I will know where the error comes from.
精彩评论