Question

Hope there are some GLKViewController experts out there because I have some problems :)

Just a quick description of my app. I have a UINavigationController in which I push different screens.

At some point, I get to my game screen which is a subclass of UINavigationController. In this screen, in viewDidLoad I manually create a EAGLContext, GLKView and instantiate a new GLKViewController (to handle my update&draw calls).

I am setting a preferred fps of 30.

The problem is that the first 3-4 update calls come with the correct DT, but then I have 2-3 frames with 1 second between them. I measure the DT using controller.timeSinceLastUpdate. So I get like:

dt=0.33
dt=0.33
dt=0.33
dt=1.07
dt=1.05
dt=0.33
dt=0.33

After this, I get valid only DT times. I have no idea why those frames have that kind of delay. I measured the time it takes me in the update & draw method, and it's nowhere near 1 second.

Also, I'm not loading any textures/creating any geometry. Everything is done at loading since it is a rather small game.

Also, if I pop the game screen controller and then push back another instance of the game screen, this new GLKViewController will only call my update method aproximately every 1 second.

Did anybody have a problem with the framerate when using GLKViewController?

Thanks,

Was it helpful?

Solution 2

Ok, so I finally figured it out. It turns out that it's not even related to the GLKViewController (surprise surprise!).

It had something to do with the way I'm displaying the game screen view controller, like this:

    GameAreaViewController* gameController = [[GameAreaViewController alloc] init];

    [UIView beginAnimations:@"animation" context:nil];
    [self.navigationController pushViewController: gameController animated:NO]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
    [UIView setAnimationDuration:0.7f];
    [UIView commitAnimations];        

    SAFE_DEL(gameController);

If I use an animation duration of 0.3f, then I don't get any lag. At 0.5f sometimes I get it and at 0.7 I was always getting it.

OTHER TIPS

The problem is that you don't know what else the device is doing between your refreshes :)

You might only spent 0.1s working on the next frame but if there is a memory warning then other bits of your app will also take time to process. I guess that the gl controller will do it's best to keep to the preferred frame rate but if lots is going on in the background then there's not much it can do about it.

As long as you make sure that your code is rendering as fast as possible and isn't spiking in the same way as the framerate then it's not your render path. From your question it sounds like you've already tested that.

The other thing you might want to do is to watch out for other notifications that might be passed into your app (i.e. memory warnings).

Finally, is there a pattern to the slow frames - do they coincide with a new image being loaded or a file access? Have you done as much as possible beforehand? EDIT - rereading your question makes me think that you've already done this, sorry!

Sorry I can't be any more use :(

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top