Game Development Community

iT2D 1.5 Preview 1 - Game Center Memory

by Daniel Liverance · in iTorque 2D · 07/23/2011 (3:59 pm) · 3 replies

Build: 1.5 Preview 1

Platform: Simulator, iPhone, iPad, iPod. Mac OSX 10.6.8 and XCode 4.0.1

Target: Simulator

Issues: when the script for closing Game Center executes, the program crashes in the simulator.

Steps to Repeat:

1. run an iphone app in the simulator that is using Game Center.
2. log into Game Center (fully authenticated).
3. exit the app (using home button if the app is NOT background enabled).
4. observe the crash in XCode.


Suggested Fix:

The error comes from calling dealloc inside this function.

ConsoleFunction(closeGameCenter, void, 1, 1, "() This will cleanup and close Game Center. Should only be called when the game is closed")
{
    [gameCenterManager dealloc];    // <------------------------- line 547 in GameCenter.mm
}


There is also an improper dealloc call to the view controller inside the gameCenterManager's dealloc method here.
// Main cleanup function for GameCenterManager
// This is exposed to TorqueScript via the closeGameCenter() function
- (void) dealloc
{
    // TODO - Call this from script
    gameCenterAvailable = NO;
    isAuthenticated = NO;
    
    self.achievementCache = NULL;
    
    if(gameCenterViewController != NULL)
        [gameCenterViewController dealloc]; // <--------------------------- line 151 in GameCenter.mm
    
    [super dealloc];
}

There should NEVER be ANY calls to dealloc in obj-c code unless it is [super dealloc] according to Apples Memory Management Programming Guide.

So a quick fix would be to change each dealloc call to release instead.


I also did a search for dealloc calls in the engine and found one more:

line 127 : [self dealloc];
//Notification of when the video has done playing now, and we can move on.
- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
	//Remove our observer
	[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
	[movieViewController.view removeFromSuperview];

	// Reactivate the current audio session
	AudioSessionSetActive(YES);
	//Audio::OpenALInit();
	
	//We can dealloc this whole delegate once we are done as the playback was asynchronous, which releases the movieController


	[self dealloc];  // <-------------------------------- line 127 in iPhoneMoviePlayback.mm
}

this should also be [self release];

Thanks.

About the author

I am 21 years old, and have just recently graduated from College for Game Programming (with honours) and I am now the Lead Programmer at Blinker Studios.


#1
07/25/2011 (11:33 am)
Resolved for iTorque 2D 1.5 Preview 2. Thanks for catching this Daniel. I don't know what was going through my head when I wrote that =/
#2
07/29/2011 (4:48 pm)
haha, I'm just glad I could help :)

1.5 preview 2 is looking good btw.
#3
07/30/2011 (5:07 pm)
Also, for the line of
[gameCenterManager release];

There should also be
gameCenterManager = nil;

Just because for some reason on the iPhone 3G and the iPad, this method gets called twice and if it is nil the second time around (obviously you know) it will be "ignored". (I looked for more than one call in the torque script but could only find one. It is in the endGame() function)