Cocos2d,iOS和XCode:我如何调试/理解这个堆栈跟踪?

时间:2013-02-08 10:00:01

标签: ios xcode eclipse cocos2d-iphone stack-trace

我正在开发一款Cocos2d 2.0游戏,无法安静地解决我的应用程序崩溃的原因。

控制台输出如下:

2013-02-08 10:52:08.298 AppName[994:15203] cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [29] to [40].
2013-02-08 10:52:08.299 AppName[994:15203] cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [40] to [54].
2013-02-08 10:52:08.300 AppName[994:15203] cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [54] to [73].
(lldb) 

“游戏场景”立即加载并崩溃。我可以看到这与CCSpriteBatchNode有关,但我完全不知道代码在哪里失败。如果我添加一个断点,它没有多大用处,因为它会在到达失败的确切时刻之前多次触发。

(lldb)是什么意思?有没有办法有更明确的堆栈跟踪? 我曾经在Java和Eclipse中工作,并且有可能用英语读取完整的堆栈跟踪...我认为它是使用XCode的simle。

1 个答案:

答案 0 :(得分:1)

你可能会遇到一些令人讨厌的EXC_BAD_ACCESS错误。不,没有例外。例如

@try {

//        this is caught
//        NSMutableArray *ar = [NSMutableArray array];
//        [ar addObject:nil];

//        this is caught
//        NSMutableDictionary *dic = [NSMutableDictionary dictionary] ;
//        [dic setObject:@"a" forKey:nil];

//    this crashes , no exception
//    NSLog("21");

//    and this will cause a message sent to a dealloced instance (zombie).
//    no exception, just a bad crash.

    GEIntEffect *eff = [GEIntEffect intEffectWithString:@"*1.1"
                                              withOrder:geEffectOrderFightMagic
                                              andImpact:geEffectImpactPositive];
    [eff release];
    NSLog([eff description]);


    [[GameSpecs sharedGameSpecs] setupBattlesInitialSpecs];
    // with  a comment
}

@catch (NSException *e) {
    MPLOGERROR(@"*** an exception [%@] occured while writing the game specs, continuing.\n%@\n\n%@",
    e.description,
    e.callStackSymbols,
    e.callStackReturnAddresses);
}

前两个被捕获并且日志语句是显式的,在日志中向我吐出堆栈跟踪。 NSLog(“21”)......哎呀,忘了“@”严重崩溃。第四个例子,在使用前错误地释放了一个物体......你知道那是做什么的。我只能建议你:

  • 检查所有警告(我在坏的NSLog上有一个警告)
  • 使用乐器为僵尸配置您的应用。发送给dealloced对象的消息也会崩溃。
  • 虽然存在性能损失,即不要过度使用,但是一些策略性的try / catch块可能会有很大的帮助。通常,我在Debug中包装任何'update'方法,删除Release中的try / catch。
  • 重新检查所有警告:)
祝你好运。

ps:这是我捕获异常时日志的样子。偏移不是“代码行”,符号允许这样做。但是,通常情况下,我从跟踪中获得足够的信息以将其缩小到真正的接近。 :

- [MPGameSequencer sequenceInitState]: *异常[* - [__ NSArrayM insertObject:atIndex:]:对象不能为nil]在编写游戏规范时出现,继续。 (

0   CoreFoundation                      0x028de02e __exceptionPreprocess + 206
1   libobjc.A.dylib                     0x022bbe7e objc_exception_throw + 44
2   CoreFoundation                      0x02891b6a -[__NSArrayM insertObject:atIndex:] + 314
3   CoreFoundation                      0x02891a20 -[__NSArrayM addObject:] + 64
4   Battles                             0x00221c49 -[MPGameSequencer sequenceInitState] + 809
5   Battles                             0x0021e359 -[MPGameSequencer nextFrame:] + 121
6   Battles                             0x00067324 -[CCTimer update:] + 308
7   Battles                             0x00070444 -[CCScheduler update:] + 772
8   Battles                             0x0009dc81 -[CCDirectorIOS drawScene] + 225
9   Battles                             0x0009ef44 -[CCDirectorDisplayLink mainLoop:] + 52
10  QuartzCore                          0x007c32d2 _ZN2CA7Display11DisplayLink8dispatchEyy + 110
11  QuartzCore                          0x007c375f _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 161
12  CoreFoundation                      0x0289d376 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
13  CoreFoundation                      0x0289ce06 __CFRunLoopDoTimer + 534
14  CoreFoundation                      0x02884a82 __CFRunLoopRun + 1810
15  CoreFoundation                      0x02883f44 CFRunLoopRunSpecific + 276
16  CoreFoundation                      0x02883e1b CFRunLoopRunInMode + 123
17  GraphicsServices                    0x035e57e3 GSEventRunModal + 88
18  GraphicsServices                    0x035e5668 GSEventRun + 104
19  UIKit                               0x00e9165c UIApplicationMain + 1211
20  Battles                             0x000c2bce main + 270
21  Battles                             0x00002a15 start + 53