奇怪的iOS崩溃

时间:2012-02-16 20:12:29

标签: iphone ios crash

我在设备上的发布版本中发生了非常间歇性的崩溃。这是崩溃日志的相关部分:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000f
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x357c6fbc objc_msgSend + 16
1   CoreFoundation                  0x33ff9020 CFRetain + 76
2   GraphicsServices                0x35c45af2 GSFontCreateWithName + 178
3   UIKit                           0x3514264c UINewFont + 52
4   UIKit                           0x351425fc +[UIFont systemFontOfSize:traits:] + 12
5   MyApp                           0x0002bc68 -[STDrawer createButtonWithTitle:backgroundColor:] (STDrawer.mm:284)
6   MyApp                           0x0002b8e0 -[STDrawer displayActionButtonsWithTitlesArray:] (STDrawer.mm:179)
7   MyApp                           0x0002b7e0 -[STDrawer displayActionButtonsWithTitles:] (STDrawer.mm:146)
8   MyApp                           0x0000fb72 -[STGameController playerToAct:] (STGameController.mm:940)
9   MyApp                           0x00015b16 -[STGame playerToAct:] (STGame.mm:218)
10  MyApp                           0x00018c0e -[STGameClient processMessage:arg:argLen:] (STGameClient.mm:461)
11  MyApp                           0x00017520 -[STGameClient dataReceived:] (STGameClient.mm:150)
12  MyApp                           0x0003a02c -[STLocalConnClient(STPrivate) dataReceivedFromServerCb:] (STLocalConnClient.mm:115)
13  Foundation                      0x31b7593c __NSFireDelayedPerform + 408
14  CoreFoundation                  0x34084a5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
15  CoreFoundation                  0x340846c2 __CFRunLoopDoTimer + 358
16  CoreFoundation                  0x34083298 __CFRunLoopRun + 1200
17  CoreFoundation                  0x340064d6 CFRunLoopRunSpecific + 294
18  CoreFoundation                  0x3400639e CFRunLoopRunInMode + 98
19  GraphicsServices                0x35c46fc6 GSEventRunModal + 150
20  UIKit                           0x3514b73c UIApplicationMain + 1084
21  MyApp                           0x000031c8 main (main.mm:113)
22  MyApp                           0x00002e28 start + 32

这是缩短的代码:

-(UIButton*)createButtonWithTitle: (NSString*)title backgroundColor: (UIColor*)backgroundColor
{
    ...
    UIButton* button = [[UIButton alloc] initWithFrame: CGRectZero];
    button.titleLabel.font = [UIFont systemFontOfSize: (st::STUIDims::Self())->DrawerFontSize()];
    button.titleLabel.adjustsFontSizeToFitWidth = YES;
    [button setTitle: title forState: UIControlStateNormal];
    button.backgroundColor = [UIColor clearColor];
    ...
    return [button autorelease];

}

我看到button.titleLabel.font行发生了至少4次崩溃,button.titleLabel.adjustsFontSizeToFitWidth发生了一次崩溃(后者与-[CALayer pointSize]: unrecognized selector sent to instance发生冲突)。

我认为这是一个内存问题所以我在模拟器下使用Valgrind运行应用程序,包括发布和调试版本,但没有任何结果。它在Apple的库中找到了很多东西但我的代码中没有任何内容。并且崩溃在分配后立即发生。它如何能够如此迅速地腐败?

我不知道下一步该做什么。任何建议都非常受欢迎。

编辑:这是adjustsFontSizeToFitWidth上的爆炸:

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

Last Exception Backtrace:
0   CoreFoundation                  0x33a888bf __exceptionPreprocess + 163
1   libobjc.A.dylib                 0x351a41e5 objc_exception_throw + 33
2   CoreFoundation                  0x33a8bacb -[NSObject doesNotRecognizeSelector:] + 175
3   CoreFoundation                  0x33a8a945 ___forwarding___ + 301
4   CoreFoundation                  0x339e5680 _CF_forwarding_prep_0 + 48
5   UIKit                           0x34b84107 -[UILabel setAdjustsFontSizeToFitWidth:] + 279
6   MyApp                           0x0003b7e4 -[STDrawer createButtonWithTitle:backgroundColor:] (STDrawer.mm:288)
7   MyApp                           0x0003b4a0 -[STDrawer displayActionButtonsWithTitlesArray:] (STDrawer.mm:184)
8   MyApp                           0x0003b364 -[STDrawer displayActionButtonsWithTitles:] (STDrawer.mm:147)
9   MyApp                           0x00014ba8 -[STGameController playerToAct:] (STGameController.mm:943)
10  MyApp                           0x0001c0bc -[STGame playerToAct:] (STGame.mm:219)
11  MyApp                           0x0001fa98 -[STGameClient processMessage:arg:argLen:] (STGameClient.mm:461)
12  MyApp                           0x000213b4 -[STGameClient dataReceived:] (STGameClient.mm:151)
13  MyApp                           0x00050c7c -[STLocalConnClient(STPrivate) dataReceivedFromServerCb:] (STLocalConnClient.mm:116)
14  Foundation                      0x3154d943 __NSFireDelayedPerform + 415
15  CoreFoundation                  0x33a5ca63 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 15
16  CoreFoundation                  0x33a5c6c9 __CFRunLoopDoTimer + 365
17  CoreFoundation                  0x33a5b29f __CFRunLoopRun + 1207
18  CoreFoundation                  0x339de4dd CFRunLoopRunSpecific + 301
19  CoreFoundation                  0x339de3a5 CFRunLoopRunInMode + 105
20  GraphicsServices                0x3561efcd GSEventRunModal + 157
21  UIKit                           0x34b23743 UIApplicationMain + 1091
22  MyApp                           0x000031f8 main (main.mm:121)
23  MyApp                           0x00002c90 start + 40

3 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,原来,我不小心

[self.button setImage:iconImageName forState:UIControlStateNormal];

使用NSString而不是UIImage设置图像

答案 1 :(得分:1)

尝试在设置字体的行之前记录(st::STUIDims::Self())->DrawerFontSize()

答案 2 :(得分:1)

我正在回答这个问题,以防有人遇到类似的问题。

乐器泄漏,僵尸,Malloc Guard,-fstack-protector,Valgrind都干净利落,模拟器中从未出现过问题。

问题是我有三个4 MB的图像(加上一大堆较小的图像)同时都在踢。一旦我把大的那些转换成PNG-8(缩小到原来的大约一半)并且我在任何时候只保持一个装载,问题就消失了。如果分配超过一定数量的内存并且内存开始不足,那么iOS似乎很有趣。

无论如何,我进行了12小时自动测试并且没有崩溃。

感谢所有人的帮助。