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 8020331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:40:02+00:00 2026-06-04T21:40:02+00:00

I am working on a simple iOS game and I am having a problem

  • 0

I am working on a simple iOS game and I am having a problem with UINavigationController and an EAGL-View.
The situation is as follows: I use one EAGL-View in conjunction with multiple controllers.
Whenever I push the MainViewController (which does all the custom openGL drawing), I end up using more memory (around 5MB per push!).

The problem seems to be within [eaglView_ setFramebuffer] – or at least that’s where almost all allocations seem to happen (I’ve checked the live bytes via Instruments – around 70% of memory is allocated in this function).

EAGLView::setFramebuffer:

- (void)setFramebuffer {
    if (context) {
        [EAGLContext setCurrentContext:context];

        if (!defaultFramebuffer)
             [self createFramebuffer];

        glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
        glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebuffer);         
        glViewport(0, 0, framebufferWidth, framebufferHeight);
    }
}

and EAGLView::createFramebuffer:

- (void)createFramebuffer
{
    if (context && !defaultFramebuffer) {
        [EAGLContext setCurrentContext:context];

        // Create default framebuffer object.
        glGenFramebuffers(1, &defaultFramebuffer);
        glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);

        // Create color render buffer and allocate backing store.
        glGenRenderbuffers(1, &colorRenderbuffer);
        glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
        [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth);
        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);

        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);

        //MSAA stuff
        glGenFramebuffers(1, &msaaFramebuffer);
        glGenRenderbuffers(1, &msaaRenderBuffer);
        glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebuffer);
        glBindRenderbuffer(GL_RENDERBUFFER, msaaRenderBuffer);

        glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_RGBA8_OES, framebufferWidth, framebufferHeight);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, msaaRenderBuffer);

        glGenRenderbuffers(1, &msaaDepthBuffer);      
        glBindRenderbuffer(GL_RENDERBUFFER, msaaDepthBuffer);
        glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16, framebufferWidth, framebufferHeight);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, msaaDepthBuffer);

        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
            NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));

    }
}

As you can see – nothing special there.
I switch my ViewControllers like this: (in the AppDelegate)

- (void) swichToViewController: (UIViewController*) newViewController overlapCurrentView: (bool) overlap {
  // get the viewController on top of the stack - popViewController doesn't do anything if it's the rootViewController.
  if(!overlap) {
    // clear everything that was on the eaglView before 
    [eaglView_ clearFramebuffer];
    [eaglView_ applyMSAA];
    [eaglView_ presentFramebuffer];         
  }

  UIViewController* oldViewController = [navController_ topViewController];
  // see if the view to be switched to is already the top controller:
  if(oldViewController == newViewController)
    return;
  // if the view is already on the stack, just remove all views on top of it:
  if([[navController_ viewControllers] containsObject:newViewController]) {
    [oldViewController setView:nil];
    [newViewController setView:eaglView_];
    [navController_ popToViewController:newViewController animated:!overlap];
    return;
  }
  // else push the new controller
  [navController_ popViewControllerAnimated:NO];
  [oldViewController setView:nil];
  [newViewController setView:eaglView_];
  [navController_ pushViewController:newViewController animated:!overlap];
}

Finally, I render my sprites like this: (In my MainViewController.mm):

- (void)drawFrame
{
  // When I delete this line, I just get a white screen, even if I have called setFramebuffer earlier(?!)
  [(EAGLView *)self.view setFramebuffer];

  glClearColor(1, 1, 1, 1);
  glClear(GL_COLOR_BUFFER_BIT); 

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();


  GLfloat screenWidth = [UIScreen mainScreen].bounds.size.width;
  GLfloat screenHeight = [UIScreen mainScreen].bounds.size.height;

  glOrthof(0, screenWidth, 0, screenHeight, -1.0, 1.0);
  glViewport(0, 0, screenWidth, screenHeight);

  [gameManager_ playGame];


  //MSAA stuff
  [(EAGLView *)self.view applyMSAA];

  [(EAGLView *)self.view presentFramebuffer];
  [(EAGLView *)self.view clearFramebuffer];
}

Something that might be worth mentioning is that I don’t allocate the views every time I push them, I keep references to them until the game exits.

[gameManager_ playGame] draws the sprites to the screen – but I’ve used this method in another project without any memory problems.

Any help would be really appreciated as I’ve been stuck on this for 2 days :/

Edit:
I’ve been able to narrow the problem down to a call to gldLoadFramebuffer. This is called whenever I try to draw something on the screen using an openGL function.
It seems to consume more memory when the context changes… But how could I avoid that?

  • 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-06-04T21:40:04+00:00Added an answer on June 4, 2026 at 9:40 pm

    I think I found the problem.
    For anyone interested: The MSAA-Buffers weren’t correctly deleted on switching the views. That caused the performance to drop significantly after a few pushes, and was also responsible for the increase in memory usage.

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

Sidebar

Related Questions

I am working on a simple Table View iOS application, and I want to
Currently i am working in Simple game application, i have a doubt on glVertexAttribPointer
I am working on a simple universal ios app that displays images in a
I'm working on a quite simple native extension for Adobe Air powered iOS app.
I'm working on an iOS app where I use third party libraries. I want
i'm trying to come up with a simple game on iOS and i's stuck
I was working on a simple game app using Xcode, but when I saw
i'm working on a little iOS project, and i stumbled across a problem with
I am working on a iOS application, the model is very simple (Folders and
I'm working on a simple game to experience the multiplayer game development on mobile

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.