GameCenter function crashes app - can anyone help to solve?


I have a crash log for my current iPhone app which is symbolicated, but I am having trouble deciphering what the problem is still.

The basic issue is that on certain devices (particularly older ones) my app with crash back to the home screen. It appears to be when a user comes back to my game after a while - which initiates a login process to the Game Center. I have pasted the relevant part of the crash log below:

Exception Codes: KERN_INVALID_ADDRESS at 0x2e000000
Crashed Thread:  0

Thread 0 name:  Dispatch queue:
Thread 0 Crashed:
0   libobjc.A.dylib                 0x37c11f7e objc_msgSend + 22
1   Transfer Quiz                   0x000023c4 -[GameCenterManager callDelegate:withArg:error:] (GameCenterManager.m:113)
2   Transfer Quiz                   0x0000230c __60-[GameCenterManager callDelegateOnMainThread:withArg:error:]_block_invoke_0 (GameCenterManager.m:103)
3   libdispatch.dylib               0x346fdc52 _dispatch_call_block_and_release + 6
4   libdispatch.dylib               0x346ffee0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 188
5   CoreFoundation                  0x358432a6 __CFRunLoopRun + 1262
6   CoreFoundation                  0x357c649e CFRunLoopRunSpecific + 294
7   CoreFoundation                  0x357c6366 CFRunLoopRunInMode + 98
8   GraphicsServices                0x37462432 GSEventRunModal + 130
9   UIKit                           0x332d2cce UIApplicationMain + 1074
10  Transfer Quiz                   0x000030d4 main (main.m:16)
11  Transfer Quiz                   0x000021a8 start + 32

and here is the following code for GameCenterManager callDelegate:

- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
assert([NSThread isMainThread]);
if([delegate respondsToSelector: selector])
    if(arg != NULL)
        [delegate performSelector: selector withObject: arg withObject: err];
        [delegate performSelector: selector withObject: err];
    NSLog(@"Missed Method");

The code was part of a tutorial on an external tutorial website - and I cannot pinpoint the issue that's causing my app to crash here.

Does anyone know of a reason why code is causing the crash? Any help would be much appreciated. I am finding it very hard to replicate the crash on any device and using NSZombies is also not working probably due to my inability to recreate the crash.

Thank you all, in advance.

asked on Stack Overflow Sep 9, 2012 by user1309044

1 Answer


It seems that the selector you're calling takes 2 arguments: an 'arg' and an 'error'. Now the thing is that if 'arg' is nil, you're calling the selector to one argument only - so the second argument is basically garbage, and when the object on which the selector is called tries to access the second argument, it crashes. All in all, you don't need that if() - always pass both arguments to the selector and let the delegate detect if its first argument is nil.

answered on Stack Overflow Sep 9, 2012 by (unknown user)

User contributions licensed under CC BY-SA 3.0