0
votes

Trying to present my GKGameCenterViewController. It works fine in iOS 7, but when i try to.....

GKGameCenterViewController *gamecenterViewController = [[GKGameCenterViewController alloc]init];
gamecenterViewController.viewState = GKGameCenterViewControllerStateDefault;
gamecenterViewController.gameCenterDelegate = self;
[[CCDirector sharedDirector] presentModalViewController:gamecenterViewController animated:YES];

...in iOS 6, i get a iOS 6 EXC_BAD_ACCESS (code=2, address=0x15) error.

I've tried stepping in, but seems to step through ok until it gets to the funny looking code...enter image description here

I've read many pre-existing and similar faults, but most seem to report additional output from the debugger, but I'm simply not getting anything more than the above quoted error...


This is my bt output after the crash took place..

(lldb) bt

*thread #1: tid = 0x697d9, 0x024a709b libobjc.A.dylib`objc_msgSend + 15, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x47)

frame #0: 0x024a709b libobjc.A.dylib`objc_msgSend + 15

frame #1: 0x0222fb4b GameKit`__55-[GKGameCenterViewController _setupChildViewController]_block_invoke_083 + 42

frame #2: 0x0222b896 GameKit`__61-[GKHostedViewController requestRemoteViewControllerIfNeeded]_block_invoke_0113 + 1167

frame #3: 0x00c9e48f UIKit`__block_global_11 + 154

frame #4: 0x026cd731 libdispatch.dylib`_dispatch_barrier_sync_f_slow_invoke + 89

frame #5: 0x026dc014 libdispatch.dylib`_dispatch_client_callout + 14

frame #6: 0x026cc7d5 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 296

frame #7: 0x038bdaf5 CoreFoundation`__CFRunLoopRun + 1925

frame #8: 0x038bcf44 CoreFoundation`CFRunLoopRunSpecific + 276

frame #9: 0x038bce1b CoreFoundation`CFRunLoopRunInMode + 123

frame #10: 0x03c027e3 GraphicsServices`GSEventRunModal + 88

frame #11: 0x03c02668 GraphicsServices`GSEventRun + 104

frame #12: 0x007bfffc UIKit`UIApplicationMain + 1211   * frame #13: 0x0008c0d6 Monkey Puzzle`main(argc=1, argv=0xbffff040) + 134 at main.m:14 (lldb)

With Zombies turned on in the debug menu, the Backtrace looks slightly different

(lldb) bt

*thread #1: tid = 0x6fb94, 0x02b35286 libsystem_kernel.dylib`__kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGKILL

frame #0: 0x02b35286 libsystem_kernel.dylib`__kill + 10

frame #1: 0x02b335ec libsystem_kernel.dylib`kill$UNIX2003 + 32

frame #2: 0x03907aac CoreFoundation`___forwarding___ + 316

frame #3: 0x0390794e CoreFoundation`__forwarding_prep_0___ + 14

frame #4: 0x02230b4b GameKit`__55-[GKGameCenterViewController _setupChildViewController]_block_invoke_083 + 42

frame #5: 0x0222c896 GameKit`__61-[GKHostedViewController requestRemoteViewControllerIfNeeded]_block_invoke_0113 + 1167

frame #6: 0x00c9f48f UIKit`__block_global_11 + 154

frame #7: 0x026ce731 libdispatch.dylib`_dispatch_barrier_sync_f_slow_invoke + 89

frame #8: 0x026dd014 libdispatch.dylib`_dispatch_client_callout + 14

frame #9: 0x026cd7d5 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 296

frame #10: 0x038beaf5 CoreFoundation`__CFRunLoopRun + 1925

frame #11: 0x038bdf44 CoreFoundation`CFRunLoopRunSpecific + 276

frame #12: 0x038bde1b CoreFoundation`CFRunLoopRunInMode + 123

frame #13: 0x03c037e3 GraphicsServices`GSEventRunModal + 88

frame #14: 0x03c03668 GraphicsServices`GSEventRun + 104

frame #15: 0x007c0ffc UIKit`UIApplicationMain + 1211   * frame #16: 0x0008cba6 Monkey Puzzle`main(argc=1, argv=0xbffff00c) + 134 at main.m:14 (lldb)

When doing a Product/Profile/Zombies run, I received this after pressing the button in my menu at the 40 second mark...

enter image description hereenter image description here

Any advice please?

1
type bt into the debug console. this gives you a backtrace. if this doesn't solve your problem, post the backtrace and maybe someone can help...Michael
Backtrace Added, thanks @MichaelphpN00b
all i can see is that this is a dangling pointer problem. to get a good grasp of what is going on i fear you have to RTFB (read the fabulous binary) ;) or maybe someone had a similar problem in the past and can help youMichael
In the zombies version, do you also get a log in the debug console that says something about a message being sent to a deallocated instance? (If so, paste it into the question or a comment.)Phillip Mills
Zombies is most likely what you're looking for. Give an hour or two, read up on NSZombies and how to effectively use them.khanh.tran.vinh

1 Answers

0
votes

OK fixed it....

I have a method in a custom class that handles weather or not to bring up all leaderboards or a specific one... here is one example of how i call it...

-(void)displayLeaderboard:(id)sender
{
    [[ABGameKitHelper sharedHelper] showLeaderboard:@""];
}

If i pass an empty string to it, its meant to show just the gamcenter main screen, with all the leaderboards. If i send it any string, it will show the default leaderboard ("level 1"), and if i pass it a valid leaderboardID, it will show that leaderboard....

Used to look like this...

-(void) showLeaderboard:(NSString*)leaderboardId
{
    GKGameCenterViewController *gamecenterViewController = [[GKGameCenterViewController alloc]init];
    GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc]init];

    if ([leaderboardId isEqualToString:@""])
    {
        gamecenterViewController.viewState = GKGameCenterViewControllerStateDefault;
        gamecenterViewController.gameCenterDelegate = self;
        [[self topViewController] presentViewController:gamecenterViewController animated:YES completion:nil];
    }
    else
    {
        leaderboardViewController.leaderboardDelegate = self;
        leaderboardViewController.category = leaderboardId;
        [[self topViewController] presentViewController:leaderboardViewController animated:YES completion:nil];
    }
}

This worked FINE on iOS 7, however iOS 6 would crash with the information i provided in the above question.

It turns out that the solution was to include the definition inside the if statement. I have no idea why iOS 6 isn't happy with declaring both of them, and only using one... The only reason i noticed something was us was because i saw [GKLeaderboardViewController _endDelayingPresentation]: message sent to deallocated instance 0xaac8d20 in the debug, when (although similar) i was actually always only ever needing to call the GKGameCenterViewController... So moving the declarations to within the IF statement solved this issue that would have otherwise not allowed me to deploy to iOS 6...

I would really love to read some comments on this to help me understand obj-c a little better, thanks....