Cocos2d,iOS和XCode:我如何调试/理解这个stacktrace? [英] Cocos2d, iOS and XCode: how can I debug/understand this stacktrace?

查看:1561
本文介绍了Cocos2d,iOS和XCode:我如何调试/理解这个stacktrace?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



控制台输出如下:

我在开发一个Cocos2d 2.0游戏,不能安静地解决为什么我的应用程序崩溃。

  2013-02-08 10:52:08.298 AppName [994:15203] cocos2d:CCSpriteBatchNode:将TextureAtlas容量从[29] ]。 
2013-02-08 10:52:08.299 AppName [994:15203] cocos2d:CCSpriteBatchNode:将TextureAtlas容量从[40]调整为[54]。
2013-02-08 10:52:08.300 AppName [994:15203] cocos2d:CCSpriteBatchNode:将TextureAtlas容量从[54]调整为[73]。
(lldb)

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



(lldb )是什么意思?有没有办法有一个更明确的栈跟踪? 我曾经在Java和Eclipse工作,有可能用英语阅读完整的stacktrace ..我想它是simle使用XCode。

解决方案

你可能得到了一个讨厌的EXC_BAD_ACCESS bugger。不,没有例外。例如

  @try {

//捕获到
// NSMutableArray * ar = [NSMutableArray array];
// [ar addObject:nil];

//被捕获
// NSMutableDictionary * dic = [NSMutableDictionary dictionary];
// [dic setObject:@aforKey:nil];

//崩溃,没有异常
// NSLog(21);

//这将导致一个消息发送到被释放的实例(僵尸)。
//没有例外,只是一个坏的崩溃。

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


[[GameSpecs sharedGameSpecs] setupBattlesInitialSpecs];
//带注释
}

@catch(NSException * e){
MPLOGERROR(@***一个异常[%@]游戏规格,继续。\\\
%@ \\\
\\\
%@,
e.description,
e.callStackSymbols,
e.callStackReturnAddresses);
}

前两个被捕获,日志语句是显式的,跟踪在日志中。 NSLog(21)... ooops,忘了@崩溃了严重。第四个例子,错误地释放一个对象使用之前...好,u知道是什么。我只能建议你:




  • 检查所有警告(我有一个坏的NSLog)

  • 为你的僵尸配置你的应用程序,使用仪器。

  • 虽然有一个性能损失,即不要超过它,一些策略性放置的try / catch块可以帮助非常大。通常,我在Debug中封装任何update方法,删除Release中的try / catch。

  • 重新检查所有警告:)



最好的运气。



ps:这是我捕获异常时日志的样子。偏移不是代码行,符号化允许这样。但是,通常,我有足够的信息从痕迹,把它缩小到真正接近。 :



- [MPGameSequencer sequenceInitState]: *异常[* - [__ NSArrayM insertObject:atIndex:]:object不能为nil]写游戏规格,继续。



  0的CoreFoundation 0x028de02e __exceptionPreprocess + 206 
1 libobjc.A.dylib 0x022bbe7e objc_exception_throw + $ 44 b $ b 2的CoreFoundation 0x02891b6a - [__ NSArrayM insertObject:atIndex:] + 314
3的CoreFoundation 0x02891a20 - [__ NSArrayM ADDOBJECT:] + 64
4战役0x00221c49 - [MPGameSequencer sequenceInitState] + 809
5战役0x0021e359 - [MPGameSequencer nextFrame:] + 121
6战0x00067324 - [CCTimer更新:] + 308
7战0x00070444 - [CCScheduler更新:] + 772
8战役0x0009dc81 - [CCDirectorIOS drawScene函数] + 225
9战役0x0009ef44 - [CCDirectorDisplayLink主循环:] + 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 b $ b 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 b $ b 18 GraphicsServices 0x035e5668 GSEventRun + 104
19 UIKit 0x00e9165c UIApplicationMain + 1211
20战斗0x000c2bce主+ 270
21战斗0x00002a15开始+ 53


I am developing a Cocos2d 2.0 game and can't quiet get around on why my App is crashing.

The console output is as following:

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) 

The "game scene" loads and crashes immediately. I can see that has to do with CCSpriteBatchNode but I have absolutely no idea on where exactly the code fails. If I add a breakpoint it is not of much use as it will trigger way to many times before reaching the exact moment when it fails.

What does (lldb) mean? Is there a way to have a more explicit stacktrace? I used to work in Java and Eclipse and there was possible to read in English the full stacktrace.. I whish it was as simle using XCode.

解决方案

You are probably getting one of those nasty EXC_BAD_ACCESS buggers. nope, no exceptions. For example

@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);
}

the first two are trapped and the log statement is explicit, spewing me the stack trace in the log. The NSLog("21") ... ooops, forgot the "@" crashes badly. The fourth example, wrongly releasing an object before use ... well u know what that does. I can only suggest you :

  • check all your warnings (i had one on the bad NSLog)
  • Profile your app for zombies, using instruments. A message sent to a dealloced object will also crash nasty.
  • although there is a performance penalty, ie dont overdo it, some strategically placed try/catch blocks can help immensely. Typically, i wrap any 'update' method in Debug, removing the try/catch in Release.
  • recheck all your warnings :)

best of luck.

ps : here is what the log looks like when i trap an exception. The offsets are not to a 'line of code', symbolicating allows for that. But, typically, i have enough info from the trace to narrow it down to real close. :

-[MPGameSequencer sequenceInitState] : * an exception [* -[__NSArrayM insertObject:atIndex:]: object cannot be nil] occured while writing the game specs, continuing. (

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

)

这篇关于Cocos2d,iOS和XCode:我如何调试/理解这个stacktrace?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆