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

  • Home
  • SEARCH
  • 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 6665291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:42:28+00:00 2026-05-26T02:42:28+00:00

I have a Cocos2d game scene that loads with an EAGLView loaded by a

  • 0

I have a Cocos2d game scene that loads with an EAGLView loaded by a UIViewController, but when I exit the game scene back to a UIKit Menu, my game scene is being deallocated in a weird way. I think if I made the game purely in Cocos2d without combining it with UIKit, this would not happen. If I call pause on CCDirector when UIViewController pops, I found that if I want to reenter the game scene, the UIViewController will load again, and simply resuming CCDirector will show a blank screen with an OpenGL error. If try [[CCDirector sharedDirector] runWithScene] it says I cannot do that if a scene is already running, but if I try replaceScene, it says that a dealloc message (for a CCSprite, no idea which one) is being sent to a deallocated instance. Here is some of my code:

- (void)viewDidLoad {
    [super viewDidLoad];
    glView = [EAGLView viewWithFrame:self.view.bounds
                         pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
                         depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
              ];
    glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view insertSubview:glView atIndex:0];
    [[CCDirector sharedDirector] setOpenGLView:glView];

    if (![[CCDirector sharedDirector] runningScene]) {
        CCScene *scene = [GameLayer scene];
        [[CCDirector sharedDirector] runWithScene:scene];
    }
    else {
        [self.view insertSubview:[[CCDirector sharedDirector] openGLView] atIndex:0];
        [[CCDirector sharedDirector] resume];    // Pause is in viewWillDisappear

        // If I replace resume with below, I get message sent to deallocated instance
        [[CCDirector sharedDirector] replaceScene:scene];
    }
}

If I run it like this, I get EXC_BAD_ACCESS inside CCTextureAtlas in the line with glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*)(start*6*sizeof(indices_[0])));

If I run it without reinitializing the glview, only initializing the first time, like if (![[CCDirector sharedDirector]openGLView]) initialize, I get a blank screen and OpenGL error 0x0506 in -[EAGLView swapBuffers].

How would I either retain my scene without doing something too contorted, or cleanly release my scene so that I may reload it with [[CCDirected sharedDirector] runWithScene]?

  • 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-26T02:42:28+00:00Added an answer on May 26, 2026 at 2:42 am

    How do you “exit the scene”? This would be the more interesting code to have a look at.

    Here’s what I found strange about the code you posted:

    - (void)viewDidLoad {
        … 
    
        if (![[CCDirector sharedDirector] runningScene]) {
            ...
        }
        else {
            // Where does this scene variable come from?
            [[CCDirector sharedDirector] replaceScene:scene];
        }
    }
    

    Normally when you run replaceScene you provide a new scene. It’s possible that you try to replaceScene with the same scene that is also the currently running scene. This will certainly crash cocos2d. If you want the same scene to re-appear, either don’t call replaceScene or create the scene anew.

    You also will want to check that the currently running scene does not dealloc. Set a breakpoint in the dealloc method of the scene. If it deallocs you probably fell for the misconception that you have to wipe the cocos2d scene from memory. You should not do that, I believe cocos2d always expects there to be at least one running scene after you called runWithScene.

    For what it’s worth, you will want to use startAnimation and stopAnimation instead of pause and resume. This will entirely halt Cocos2D without releasing the scene, so it works the same as pause/resume. My guess is that internally it shuts down the game loop altogether whereas pause/resume keeps it running at a very slow rate, ie 4 fps if I remember correctly.

    I’ve had cases where pause/resume would cause the “OpenGL error 0x0506 in -[EAGLView swapBuffers]” and startAnimation/stopAnimation would fix that.

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

Sidebar

Related Questions

I have some assets for my game that are being loaded when the gameplay
I'm making a game with cocos2d and I have a bunch of sprites that
Hi guys I am new to the cocos2D.In my game i have one scene
I am newbie to Cocos2d. I have this layer that represents my main game
I have a cocos2d game with a CCLayer called GameplayLayer placed inside a scene.
I have a cocos2d project with some scenes (home scene, level selection scene, game
I have writing a small shooting game in cocos2d. Winning the game is to
I have a very simple game using Xcode v4.2.1, Cocos2d v5.0.1. I've tried both
I have a Cocos2d/openGL iPhone game. It's a universal app and I'm dealing with
I just finish my iPhone game using cocos2d. But before I put it on

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.