-2

我正在为 iPhone 和 iPad 开发一个刽子手游戏,但有时它会崩溃。这是 Xcode 的崩溃日志:

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

Last Exception Backtrace: 
0   CoreFoundation              0x353e788f `__exceptionPreprocess`+ 163 
1   libobjc.A.dylib                 0x3778e259 objc_exception_throw + 33 
2   CoreFoundation                  0x353e7789 +[NSException raise:format:] + 1 
3   CoreFoundation                  0x353e77ab +[NSException raise:format:] + 35
4   CoreFoundation                  0x35354fed`-[__NSCFString characterAtIndex:]`+ 89
5   Poke Hangman                    0x000e41f5 -[ViewController setStringWithDatabase::](ViewController.m:194)
6   Poke Hangman                    0x000e388b -[ViewController preparaStringhe:] (ViewController.m:39)
7   Poke Hangman                    0x000e4685 -[ViewController cambia] (ViewController.m:248)
8   Poke Hangman                    0x000e3bc5 -[ViewController checkChar:] (ViewController.m:81)
9   Poke Hangman                    0x000e6155 -[ViewController ButtonG:] (ViewController.m:579)
10  CoreFoundation                  0x353413fd -[NSObject performSelector:withObject:withObject:] + 53
11  UIKit                           0x32e36e07 -[UIApplication sendAction:to:from:forEvent:] + 63
12  UIKit                           0x32e36dc3 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 31
13  UIKit                           0x32e36da1 -[UIControl sendAction:to:forEvent:] + 45
14  UIKit                           0x32e36b11 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 493
15  UIKit                           0x32e37449 -[UIControl touchesEnded:withEvent:] + 477
16  UIKit                           0x32e3592b -[UIWindow _sendTouchesForEvent:] + 319
17  UIKit                           0x32e35319 -[UIWindow sendEvent:] + 381
18  UIKit                           0x32e1b695 -[UIApplication sendEvent:] + 357
19  UIKit                           0x32e1af3b _UIApplicationHandleEvent + 5827
20  GraphicsServices                0x36fda22b PurpleEventCallback + 883
21  CoreFoundation                  0x353bb523 <br>`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__`+ 39
22  CoreFoundation                  0x353bb4c5 __CFRunLoopDoSource1 + 141
23  CoreFoundation                  0x353ba313 __CFRunLoopRun + 1371
24  CoreFoundation                  0x3533d4a5 CFRunLoopRunSpecific + 301
25  CoreFoundation                  0x3533d36d CFRunLoopRunInMode + 105
26  GraphicsServices                0x36fd9439 GSEventRunModal + 137
27  UIKit                           0x32e49cd5 UIApplicationMain + 1081
28  Poke Hangman                    0x000e3263 main (main.m:16)
29  Poke Hangman                    0x000e3208 start + 40


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x35c9d32c __pthread_kill + 8
1   libsystem_c.dylib               0x327e9208 pthread_kill + 48
2   libsystem_c.dylib               0x327e2298 abort + 88
3   libc++abi.dylib                 0x3579ff64 abort_message + 40
4   libc++abi.dylib                 0x3579d346 _ZL17default_terminatev + 18
5   libobjc.A.dylib                 0x3778e350 _objc_terminate + 140
6   libc++abi.dylib                 0x3579d3be _ZL19safe_handler_callerPFvvE + 70
7   libc++abi.dylib                 0x3579d44a std::terminate() + 14
8   libc++abi.dylib                 0x3579e81e __cxa_rethrow + 82
9   libobjc.A.dylib                 0x3778e2a2 objc_exception_rethrow + 6
10  CoreFoundation                  0x3533d506 CFRunLoopRunSpecific + 398
11  CoreFoundation                  0x3533d366 CFRunLoopRunInMode + 98
12  GraphicsServices                0x36fd9432 GSEventRunModal + 130
13  UIKit                           0x32e49cce UIApplicationMain + 1074
14  Poke Hangman                    0x000e325c main (main.m:16)
15  Poke Hangman                    0x000e3200 start + 32

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x35c8d3a8 kevent + 24
1   libdispatch.dylib               0x34277f04 _dispatch_mgr_invoke + 708
2   libdispatch.dylib               0x34277c22 _dispatch_mgr_thread + 30

Thread 2 name:  WebThread
Thread 2:
0   libsystem_kernel.dylib          0x35c8d004 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x35c8d1fa mach_msg + 50
2   CoreFoundation                  0x353bb3ec __CFRunLoopServiceMachPort + 120
3   CoreFoundation                  0x353ba124 __CFRunLoopRun + 876
4   CoreFoundation                  0x3533d49e CFRunLoopRunSpecific + 294
5   CoreFoundation                  0x3533d366 CFRunLoopRunInMode + 98
6   WebCore                         0x3123cc9c _ZL12RunWebThreadPv + 396
7   libsystem_c.dylib               0x327aa72e _pthread_start + 314
8   libsystem_c.dylib               0x327aa5e8 thread_start + 0

Thread 0 crashed with ARM Thread State:
    r0: 0x00000000    r1: 0x00000000      r2: 0x00000001      r3: 0x00000000
    r4: 0x00000006    r5: 0x3e9f4d98      r6: 0x00000002      r7: 0x2fee09f0
    r8: 0x002ad500    r9: 0x00000000     r10: 0x3ee51bc0     r11: 0x00000001
    ip: 0x00000148    sp: 0x2fee09e4      lr: 0x327e920f      pc: 0x35c9d32c
  cpsr: 0x00000010

解决了这个问题,但有了一个新问题:

这是崩溃日志:

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

Last Exception Backtrace:
0   CoreFoundation                  0x39ee717b`__exceptionPreprocess +`163
1   libobjc.A.dylib                 0x34ea095b objc_exception_throw + 31
2   CoreFoundation                  0x39ee709d -[NSException initWithCoder:] + 1
3   CoreFoundation                  0x39e4bd5b -[__NSCFString characterAtIndex:] + 87
4   Poke Hangman                    0x00077493 0x74000 + 13459
5   Poke Hangman                    0x0007644b 0x74000 + 9291
6   Poke Hangman                    0x00077a35 0x74000 + 14901
7   Poke Hangman                    0x00076839 0x74000 + 10297
8   Poke Hangman                    0x0007aa7b 0x74000 + 27259
9   UIKit                           0x32e4dd09 -[UIApplication sendAction:to:from:forEvent:] + 73
10  UIKit                           0x32e4dcbb -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 31
11  UIKit                           0x32e4dc95 -[UIControl sendAction:to:forEvent:] + 45
12  UIKit                           0x32e4d9eb -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
13  UIKit                           0x32e4e369 -[UIControl touchesEnded:withEvent:] + 489
14  UIKit                           0x32e4c791 -[UIWindow _sendTouchesForEvent:] + 525
15  UIKit                           0x32e3a72d -[UIApplication sendEvent:] + 381
16  UIKit                           0x32e3a009 _UIApplicationHandleEvent + 6057
17  GraphicsServices                0x33f04603 _PurpleEventCallback + 591
18  GraphicsServices                0x33f04233 PurpleEventCallback + 35
19  CoreFoundation                  0x39eb7873 `__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__`+ 35
20  CoreFoundation                  0x39eb7817 __CFRunLoopDoSource1 + 139
21  CoreFoundation                  0x39eb6611 __CFRunLoopRun + 1385
22  CoreFoundation                  0x39e33be5 CFRunLoopRunSpecific + 357
23  CoreFoundation                  0x39e33a71 CFRunLoopRunInMode + 105
24  GraphicsServices                0x33f0334b GSEventRunModal + 75
25  UIKit                           0x32e607f5 UIApplicationMain + 1121
26  Poke Hangman                    0x00075f65 0x74000 + 8037
27  Poke Hangman                    0x00075f00 0x74000 + 7936

请帮我找到问题..

这是我认为它崩溃的部分:isPresent 告诉用户字符是否存在于单词中,如果用户字符存在于正确的单词中,在被批评的单词中,它会在位置 i 处交换。如果没有字符,分数会降低 20。对不起我的英语不好,希望你能帮助我;)

bool isPresent = NO;

for (int i = 0; i < correctWord.length; i++)

    if (userCharFromButton == [correctWord characterAtIndex:i])
    {
        criptedWord = [criptedWord stringByReplacingCharactersInRange:NSMakeRange(i, 1.0) withString:[NSString stringWithFormat:@"%c", userCharFromButton]];
        isPresent = YES;
    }    

word.text = criptedWord;

if (isPresent == NO)
    currentlyScore -= 20;


//check if the word is complete
bool complete = YES;

for (int i = 1; i < criptedWord.length; i++)
    if ([criptedWord characterAtIndex:i] == '-')
        complete = NO;
4

1 回答 1

2

崩溃日志显示已被符号化的回溯。从那里,您可以在 Last Exception Backtrace 的第 5 项中看到

5   Poke Hangman                    0x000e41f5 -[ViewController setStringWithDatabase::](ViewController.m:194)

它位于第 194 行的 ViewController 类中的 setStringWithDatabase:: 中,导致异常。

在上面的行中,您可以看到

4   CoreFoundation                  0x35354fed`-[__NSCFString characterAtIndex:]`+ 89

所以你的 setStringWithDatabase:: 必须调用一个 CoreFoundation characterAtIndex: 方法,你直接调用你自己或者你调用的东西在你的 ViewController 类的第 194 行附近调用它。常见原因是您的字符串为 nil/空,或者您试图获取超出范围的字符。

该问题似乎与使用 ARC 无关。

[以下是第二位的解决方案]

正如我的回答中提到的,您的第二个问题似乎也与第一个问题相似。您需要确保您的字符串 criptedWord 不是 nil 并且没有与该变量相关的其他内容导致它崩溃。为了进一步诊断,您需要先符号化您的崩溃日志。

于 2012-06-20T09:37:42.857 回答