Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
CADisplayLink on iPhone 3GS and iPhone 4 drops from 60 to 40 FPS randomly
I am using CADisplayLink to perform a function called gameLoop at 60 FPS and at first the application runs perfectly. Then at a random time (could be 5 seconds or 2 minutes) the fps drops to around 40 FPS and stays there.
After days of searching forums, debugging, optimizing my rendering, profiling, and analyzing my app, I decided to remove everything from the gameLoop function except for a few lines which calculate how long it has been since the last call to gameLoop. I cannot figure out why CADisplayLink calls gameLoop at 60 FPS for a while then calls it at 40 FPS thereafter when gameLoop does almost nothing.
I implemented a pause/unpause function which invalidates the display link and restarts it. When I restart the display link, the app runs at 60 FPS again until it drops randomly.
int test = 0; - (void) gameLoop { static double lastFrameTime = 0.0f; double currentTime;
currentTime = CACurrentMediaTime(); if(currentTime - lastFrameTime > 0.025)//40 FPS or lower { test++;//after about 30 seconds I set a breakpoint here and test is always over 100+ } lastFrameTime = currentTime; }
Thanks in advance to anyone who can give me some insight as to why this is happening.
I also have problems with CADisplayLink when calling invalidate to pause it. The speed of my game changes. It actually goes faster, not slower. Very odd. I haven't checked the FPS though.
And I know for sure my game loop isn't getting called by multiple CADisplayLink instances. Calling invalidate should kill the previous one.
I am running the app on the several devices including iPhone 3GS, iPhone 4, old iPad, new iPad, and the simulator. The issue does not occur on the new iPad.
I decided to try OpenGL ES 2.0 and the GLKit API to see if that would fix the issue. After reading the apple docs and some tutorials I ported the code and tested it with the Xcode analyzer and the Performance Detective. The GLKViewController's Update and drawInRect functions get called at 60 FPS and everything runs perfectly. I just used GLKBaseEffect and did not use any shaders. Also, the code I used to draw the scene went from 7 milliseconds to only 1 mS with OpenGL ES 2.0.
I am running the app on the several devices including iPhone 3GS, iPhone 4, old iPad, new iPad, and the simulator. The issue does not occur on the new iPad.
I decided to try OpenGL ES 2.0 and the GLKit API to see if that would fix the issue. After reading the apple docs and some tutorials I ported the code and tested it with the Xcode analyzer and the Performance Detective. The GLKViewController's Update and drawInRect functions get called at 60 FPS and everything runs perfectly. I just used GLKBaseEffect and did not use any shaders. Also, the code I used to draw the scene went from 7 milliseconds to only 1 mS with OpenGL ES 2.0.
GLKit is just a wrapper for Apple's old EAGLView.m code. They still use CADisplayLink.
Replies
I also have problems with CADisplayLink when calling invalidate to pause it.
The speed of my game changes. It actually goes faster, not slower. Very odd.
I haven't checked the FPS though.
And I know for sure my game loop isn't getting called by multiple CADisplayLink instances.
Calling invalidate should kill the previous one.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeI decided to try OpenGL ES 2.0 and the GLKit API to see if that would fix the issue. After reading the apple docs and some tutorials I ported the code and tested it with the Xcode analyzer and the Performance Detective. The GLKViewController's Update and drawInRect functions get called at 60 FPS and everything runs perfectly. I just used GLKBaseEffect and did not use any shaders. Also, the code I used to draw the scene went from 7 milliseconds to only 1 mS with OpenGL ES 2.0.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- (void)updateWorld:(CADisplayLink *)sender {
CFTimeInterval deltaTime = sender.duration;
NSLog( @"deltaTime: %f fps", 1.0f / deltaTime );
}
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome