Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4038554
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:29:14+00:00 2026-05-20T12:29:14+00:00

I have a cocos2d game, it performs at between 55 and 60fps once the

  • 0

I have a cocos2d game, it performs at between 55 and 60fps once the game is loaded and running.

However, due to using sprite sheets for both my menu’s and game (one for each), there was a point of crossover when loading the game which would cause memory warnings, due to too many large png’s loaded into memory.

I implemeneted a simple CCScene to transition to for loading, (lightweight, allowing the menu to dealloc before proceeding to load the main gamescene).

This works brilliantly. However, i have hit a little road block, on my loading screen i have the main character spinning next to the word loading (to show something is happening).

I discovered that i could use NSThread to load the game in a different thread, allowing the animation of my loading scene to continue unhindered (this made for a very pleasant user experience).

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 am using this code to load my game.

Within a button –

NSThread* thread = [[[NSThread alloc] initWithTarget:self selector:@selector(goToNextScene) object:nil] autorelease];
[thread start];

The method executed in the 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 whatever is happening from happening?

The NSLock is caused when the gameScene tries to load a gamesheet.plist (framenames of individual images within teh spritesheet and co-ordinates)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:29:15+00:00Added an answer on May 20, 2026 at 12:29 pm

    You diagnosed it correctly yourself, although it’s not CCSpriteFrameCache that’s being dealloced but the CCTextureCache it relies on.

    If you created your project from the default cocos2d template, your app delegate responds to applicationDidReceiveMemoryWarning by calling [[CCDirector sharedDirector] purgeCachedData]. This in turn calls [CCTextureCache purgeSharedTextureCache], which releases and nils out the shared cache. That happens on your main app thread, and since your background thread is in the middle of using that same cache to store the textures it’s loading… boom.

    The simplest fix is just to remove that purgeCachedData call from your app delegate. You understand your app’s memory consumption better than the OS does, so rather than let the OS tell you when to purge your cache, do it yourself: Call purgeCachedData only when you know you have textures cached that you won’t be using anymore.

    From your brief description, it sounds like you would do that at the start of your transition/loading scene. Just be sure to do the purge after you create the sprites you use for your progress animation, so that their textures are kept around. (The purge call doesn’t delete anything that’s currently in use.) Likewise, be sure to do the purge before you kick off your background thread, or else you’ll get the same crash you’re seeing now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple game using Xcode v4.2.1, Cocos2d v5.0.1. I've tried both
i haves game with cocos2d i have many sprites i'm using touch to sprite
I am writing a game for the iPhone/iPodTouch (using Cocos2d) and I have noticed
I am creating a universal ios 2D game using cocos2d. I have few images
I am developing an iphone game using cocos2d and have it set to to
I have a newly created game using Cocos2D on the iPhone. I am at
I am writing an iphone game using cocos2d and box2d engines. I have a
Using cocos2d for iPhone game development, I am confused between Layer and Scene. For
I have a Cocos2d game scene that loads with an EAGLView loaded by a
I am using pushScene and popScene in my cocos2d-iphone game (1.0.1). So I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.