Weird iOS crash

2

I'm having a very intermittent crash happen in release build on device only. Here's the relevant part of the crash log:

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

This is the shortened code:

-(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];

}

I have seen at least 4 crashes from the button.titleLabel.font line and one from button.titleLabel.adjustsFontSizeToFitWidth (the latter crashed with -[CALayer pointSize]: unrecognized selector sent to instance).

I'm thinking this is a memory problem so I ran the app with Valgrind under the simulator, both release and debug builds but that turned up nothing. It finds a bunch of stuff in Apple's libraries but nothing in my code. And the crash happens immediately after allocation. How can it corrupt so quickly?

I'm not sure what to do next. Any suggestions are very welcome.

edit: this is the blowup on 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
iphone
ios
crash
asked on Stack Overflow Feb 16, 2012 by dbv • edited Feb 17, 2012 by dbv

3 Answers

2

i run into the same problem, turned out, that i accidentally

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

set the image with a NSString instead of a UIImage

answered on Stack Overflow Jul 13, 2015 by Zuzana Paulis
1

Try logging (st::STUIDims::Self())->DrawerFontSize() before the line that sets the font.

answered on Stack Overflow Feb 16, 2012 by picciano
1

I'm answering this in case someone runs into a similar problem.

Instruments Leaks, zombies, Malloc Guard, -fstack-protector, Valgrind all come out clean and there was never a problem in the simulator.

The problem was that I had three 4 MB images (plus a whole pile of smaller ones) all kicking around at the same time. Once I converted the big ones to PNG-8 (shrunk to roughly a half of the original) and I kept only one loaded at any one time, the problem went away. Seems that iOS acts funny if you allocate past a certain amount of memory and it starts running low on memory.

Anyway, I ran an automated 12 hour test and no crashes.

Thanks for all for help.

answered on Stack Overflow Feb 20, 2012 by dbv

User contributions licensed under CC BY-SA 3.0