2012-03-18 174 views
0

我的iPhone游戏在设备上崩溃,我试图了解发生了什么。了解iPhone崩溃日志

每次用户退出游戏画面,它都会发送一条消息给HomePageController(我的顶级控制器),告诉它保存用户数据。除了在这个特殊情况下,这一切都可以正常工作。抛出的异常似乎表明,HomePageController没有识别出saveUserData选择器,但我不明白这是如何发生的,因为该功能绝对在该控制器中,并且在其余时间内工作。

任何人都可以提供任何建议吗? 125

Exception Type: EXC_CRASH (SIGABRT) 
Exception Codes: 0x00000000, 0x00000000 
Crashed Thread: 0 

Last Exception Backtrace: 
0 CoreFoundation  0x3756a88f __exceptionPreprocess + 163 
1 libobjc.A.dylib  0x35a70259 objc_exception_throw + 33 
2 CoreFoundation  0x3756da9b -[NSObject doesNotRecognizeSelector:] + 175 
3 CoreFoundation  0x3756c915 ___forwarding___ + 301 
4 CoreFoundation  0x374c7650 _CF_forwarding_prep_0 + 48 
5 P------k   0x0000ebe1 -[HomePageController saveUserData] (HomePageController.m:125) 
6 P------k   0x00008a0b -[RootViewController viewDidAppear:] (RootViewController.m:102) 

线在HomePageController.m:

- (void)saveUserData{ 
    NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                    NSUserDomainMask, YES) objectAtIndex:0]; 
    //10x10 
    { 
     NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease]; 
     for (int i = 0; i < _puzzles10x10.count; i++){ 
      LevelData *currentPuzzle = [_puzzles10x10 objectAtIndex:i]; 
      /*(line 125)*/ [dict setObject:[currentPuzzle getPuzzleUserData] forKey:currentPuzzle.title]; 
     } 

     [dict writeToFile:[documentsPath stringByAppendingPathComponent:@"userdata.dat"] atomically:YES]; 
    } 
    // more here 
} 
+2

你可以在你的HomePageController.m文件中发布什么是125行吗?我想你会在那里找到你的答案 – giorashc 2012-03-18 10:04:19

+0

@giorashc啊,是的,现在看起来很明显..更新问题,仍然不完全确定为什么它在该行崩溃 – Chris 2012-03-18 10:07:04

+2

RootViewController的102行也会很有趣= = – 2012-03-18 10:37:25

回答

3

如果currentPuzzle无法识别选择getPuzzleUserData那么问题是这两种中的一种:

  1. LevelData没有定义方法getPuzzleUserData
  2. currentPuzzle不是LevelData

实例添加内容时要_puzzles10x10他们实际上的LevelData实例,以检查方法是在类LevelData并没有真正定义的HomePageController和。

为了进一步调试,拆你的代码一样多的行可能的(每行一个命令),增添了不少的NSLog电话,看看会发生什么:

NSLog(@"_puzzles10x10: %@", _puzzles10x10); 
for (int i = 0; i < _puzzles10x10.count; i++){ 
    LevelData *currentPuzzle = [_puzzles10x10 objectAtIndex:i]; 
    NSLog(@"currentPuzzle#%d: %@", i, currentPuzzle); 
    UserData *userData = [currentPuzzle getPuzzleUserData]; // change UserData to the correct t class 
    NSLog(@"userData#%d: %@", i, userData); 
    NSString *key = currentPuzzle.title; 
    NSLog(@"key#%d: %@", i, key); 
    [dict setObject:userData forKey:key]; 
} 
+0

感谢答复,LevelData肯定会响应'getPuzzleUserData'。用户保存代码没有改变几个月,我只看到过这种情况发生一次 – Chris 2012-03-18 10:22:32

+0

这一切都得到输出好吧...这是我第一次看到这种崩溃发生。我可以给你看一个输出的选择,但它完全如我所料。 – Chris 2012-03-18 10:37:21

+0

如果你不能重现崩溃,那么很难调试它:)所以保持日志,直到你再次崩溃。 – sch 2012-03-18 10:49:22

0

从日志很显然,你在对象中调用一个并不存在的方法。

(2 CoreFoundation  0x3756da9b -[NSObject doesNotRecognizeSelector:] + 175) 

我认为`_puzzles10x10'的数据类型由于在代码中出错而改变为某种其他类型。

+0

我认为如果代码没有前进到第125行,这可能是崩溃的原因。不是吗? – sch 2012-03-18 10:29:08

+0

我认为可能的崩溃是在(int i = 0; i <_puzzles10x10.count; i ++)本身的行中。 – rakeshNS 2012-03-18 10:35:04