I have a cocos2d game, it works from 55 to 60 frames per second after downloading and launching the game.
However, due to the use of sprite lists for both my menu and the game (one for each), there was an intersection point when loading the game, which would cause memory warnings due to too many large pngs loaded into memory.
I implemented a simple CCScene to go to the download (easy, allowing the de-lock menu before starting to load the main game).
It works brilliantly. However, I ended up in a small road block, on my loading screen I have a main character rotating next to the word loading (to show that something is happening).
I found that I can use NSThread to load the game in another thread, allowing the animation of my loading scene to be seamless (this made it very enjoyable for the user).
However, 5-6 / 10 times, I get this error message.
Received memory warning. Level=1
*** -[NSLock dealloc]: lock (<NSLock: 0x3ded70> '(null)') deallocated while still in use
*** Break on _NSLockError() to debug.
*** -[CFDictionary setObject:forKey:]: message sent to deallocated instance 0x3decc0
I use this code to download my game.
Inside the button -
NSThread* thread = [[[NSThread alloc] initWithTarget:self selector:@selector(goToNextScene) object:nil] autorelease];
[thread start];
Method executed in new thread -
-(void) goToNextScene {
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
EAGLContext *k_context = [[[EAGLContext alloc]
initWithAPI :kEAGLRenderingAPIOpenGLES1
sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]] autorelease];
[EAGLContext setCurrentContext:k_context];
CCScene *gs = [GameEngine scene];
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.5 scene:gs]];
[autoreleasepool release];
}
Any ideas on how I can prevent this from happening?
NSLock is called when gameScene tries to load the gameet.plist file (frame names of individual images within the sprite and codes)