Losing input on iPad only after GKLeaderboardViewController is dismissed?

Member
Posts: 31
Joined: 2010.02
Post: #1
*** Fixed, see below. But, a new question has arisen. ***

I just added Game Kit leaderboards to my application and everything works properly at the moment except when I dismiss the leaderboard view when running on the iPad I lose all touch input.

Has anyone experienced this or sees something amiss in my implementation? (I'm rather new at Obj-C so most of my logic is C++ style)

Code:
void GameKitMgr::DisplayLeaderBoard( NSString* category )
{
     if( !IsGameKitReady() )
     {
          return;
     }

     //Show leaderboard.
     GKLeaderboardViewController* leaderboardController = [[GKLeaderboardViewController alloc] init];
     if( leaderboardController != nil )
     {
          NSLog( @"GameKitMgr: Displaying leaderboard in view." );

          // We are in the leaderboards.
          ENGINE.m_Gameplay.m_PlayMenuControl.m_InLeaderboards = true;

          leaderboardController.category = category;
          leaderboardController.leaderboardDelegate = ENGINE.m_View; // This is a pointer to my EAGLView controller.
          m_GameCenterView = [[UIViewController alloc] init];        // m_GameCenterView is a UIViewController pointer within the GameKitMgr class.

          UIWindow* window = [UIApplication sharedApplication].keyWindow;
          [window addSubview: m_GameCenterView.view];

          [m_GameCenterView presentModalViewController:leaderboardController animated:YES];
     }
}

Dismiss the leaderboard:
Code:
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
     ENGINE.m_GameKitMgr.HideLeaderBoard( viewController );
}
Code:
void GameKitMgr::HideLeaderBoard( GKLeaderboardViewController* leaderboardController )
{    
     if( !m_GameCenterView )
     {
          return;
     }

     NSLog( @"GameKitMgr: Removing leaderboad from view." );

     // We are out of the leaderboards.
     ENGINE.m_Gameplay.m_PlayMenuControl.m_InLeaderboards = false;
          
     // Remove the UIViewController and GKLeaderboardViewController.
     [m_GameCenterView dismissModalViewControllerAnimated:YES];
     [m_GameCenterView.view.superview removeFromSuperview];
     [m_GameCenterView release];
     m_GameCenterView = NULL;

     [leaderboardController release];
}

The leaderboads display and disappear properly on my iPhone and iPad with the above implementation. The problem only arises on my iPad when dismissing the leaderboards. I have a feeling I'm failing to release a view which is why my normal application view does not regain input on the iPad?

Any advice would be greatly appreciated.
Quote this message in a reply
Member
Posts: 31
Joined: 2010.02
Post: #2
Well I was able to fix my problem with this little work around:
Code:
void GameKitMgr::HideLeaderBoard( GKLeaderboardViewController* leaderboardController )
{    
    if( !IsGameKitAvaliable() || !m_GameCenterView )
    {
        return;
    }
    
    NSLog( @"GameKitMgr: Removing leaderboad from view." );

    // We are out of the leaderboards.
    ENGINE.m_Gameplay.m_PlayMenuControl.m_InLeaderboards = false;
        
    // Remove the UIViewController and GKLeaderboardViewController.
    [m_GameCenterView dismissModalViewControllerAnimated:YES];
    
    if( ENGINE.m_IsiPad )
    {
        [m_GameCenterView.view removeFromSuperview];
    }
    else
    {
        [m_GameCenterView.view.superview removeFromSuperview];
    }

    [m_GameCenterView release];
    m_GameCenterView = NULL;
    
    [leaderboardController release];
}

On a somewhat related note has anyone who has used Gamekit's leader boards had trouble view scores on the leader board?

I submit scores much like how it is done in Apple's sample code:
Code:
void GameKitMgr::ReportScore( int64_t score, NSString* category )
{
    if( !IsGameKitReady() )
    {
        return;
    }
    
    GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
    scoreReporter.value = score;
    
    [scoreReporter reportScoreWithCompletionHandler:^( NSError *error )
    {
        if (error != nil)
        {
            NSLog( @"GameKitMgr: Score reported successfully" );
        }
        else
        {
            NSLog(@"GameKitMgr: Failed to report score with error: %@", [error localizedDescription] );
        }
    }];
}

And, most (if not all the time) no error is reported. So, I would assume the score was sent successfully. But, when I view my leader boards all of my leader boards just say "Unable to Load" where the scores should be. My app isn't live yet, so this is all in sandbox mode. But, is this correct behavior or am I doing something incorrectly?
Quote this message in a reply
Post Reply