6

我正在 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

4

6 回答 6

2

我在 Xcode 4.2.1 和 lldb 中遇到了这个问题。切换到 gdb 解决了这个问题。

于 2011-12-05T11:06:31.717 回答
1

你有其他线程在运行吗?可能是其他东西正在修改 behavior_.behaviors 或只是在您的循环运行时修改 behavior_,但窗口非常小,除非循环运行非常缓慢。您可以尝试在循环中长时间休眠以模拟调试,并查看在调试器外部运行时是否会导致崩溃。

于 2010-05-17T10:43:04.953 回答
1

我并不清楚您的问题是什么,但本文档可能会有所帮助:

Mac OS X 调试魔法

于 2010-05-17T00:08:25.423 回答
1

我在模拟器中运行单元测试的 XCode 4 下也看到了这一点。在这一点上,我将其归结为 iOS 模拟器中某处的错误。

如果我发现更多,我会编辑这个答案。

于 2011-06-08T22:03:06.090 回答
1

在 Xcode 4 中使用调试器时,我也遇到了这种情况。我在我的代码中放置断点,在我的类中,这些类是 SenTestCase 的子类。我通过 Product -> Test in Xcode 运行。

我一直收到此声明的错误:

Node *newEntry = [[Node alloc] initWithPayload:payload];

我只发布该代码以防有人在 -alloc 或 -init 上遇到它......

当我在删除所有断点后运行 Product -> Test 时,代码运行得很好(包括上面重复调用的行)并且测试都成功完成。

仅供参考,以防有人遇到同样的情况。

于 2011-08-15T23:54:40.180 回答
0

我在放置断点的每一行都收到错误。

即使在

NSError *error = nil;

EXC_BAD_ACCESS!

没有断点的调试器运行流畅。在模拟器和设备上,运行没有问题。没有调试器也没有问题。 我正在使用 LLVM LDB 3.0。

现在我在“运行”下的方案中切换到 GDB,它就像一个魅力。

希望他们能解决这个问题,或者最终我会知道错误来自哪里。

于 2012-03-08T09:56:05.440 回答