2
\$\begingroup\$

Whenever I lose focus from my game window, I go from ~60FPS to 6000+, then when the window gains focus again, I go back to around 60 frames per second. And yes, this happens every time I run my game, including Release mode.

Here is an example log output from my game:

[INFO] [10/01/2013 22:37:42.355] Window Gained Focus!
[INFO] [10/01/2013 22:37:45.365] Frames Per Second: 60.0439
[INFO] [10/01/2013 22:37:45.365] Frame Counter: 60
[INFO] [10/01/2013 22:37:46.365] Frames Per Second: 60.0324
[INFO] [10/01/2013 22:37:46.365] Frame Counter: 60
[INFO] [10/01/2013 22:37:47.381] Frames Per Second: 59.4341
[INFO] [10/01/2013 22:37:47.382] Frame Counter: 58
[INFO] [10/01/2013 22:37:49.669] Window Lost Focus!
[INFO] [10/01/2013 22:37:50.383] Frames Per Second: 1240.02
[INFO] [10/01/2013 22:37:50.383] Frame Counter: 9561
[INFO] [10/01/2013 22:37:51.384] Frames Per Second: 1839.02
[INFO] [10/01/2013 22:37:51.384] Frame Counter: 6662
[INFO] [10/01/2013 22:37:52.77] Window Gained Focus!
[INFO] [10/01/2013 22:37:52.400] Frames Per Second: 1656.77
[INFO] [10/01/2013 22:37:52.400] Frame Counter: 34
[INFO] [10/01/2013 22:37:53.400] Frames Per Second: 1512.46
[INFO] [10/01/2013 22:37:53.400] Frame Counter: 60
[INFO] [10/01/2013 22:37:54.401] Frames Per Second: 1391.89
[INFO] [10/01/2013 22:37:54.402] Frame Counter: 60
[INFO] [10/01/2013 22:37:55.402] Frames Per Second: 1289.78
[INFO] [10/01/2013 22:37:55.402] Frame Counter: 58
[INFO] [10/01/2013 22:37:55.876] Quitting with error code: 0

The frame counter is just a simple integer that I increment every loop in the game, and then reset (and print it out) every second. Here is the implementation of my game loop, (inside the run() function), based off of this article.

Is this a problem with my loop, or is this a problem with SDL? I'm not sure why my frame rate is rocketing up.

\$\endgroup\$
3
  • \$\begingroup\$ Is your update function paired with the render function? Does it get called less if you focus away? \$\endgroup\$ Jan 10 '13 at 12:26
  • \$\begingroup\$ @VaughanHilts My update function gets called ~100 times per frame, regardless of the game's FPS (and regardless of losing focus). However, my drawing is done per-frame, therefore it is getting called 6000+ (when I lose focus) times per second. (I don't actually have any rendering code being called though) \$\endgroup\$ Jan 10 '13 at 12:30
  • \$\begingroup\$ The loop here is fairly irrelevant - all the real work, including any SDL specific stuff, is being done in functions we can't see. \$\endgroup\$
    – Kylotan
    Jan 10 '13 at 13:07
6
\$\begingroup\$

60 fps in focus mode is very suspicious, it must be vsync.

Why vsync is turned off when the app loses focus is not a question I can answer though.

\$\endgroup\$
1
  • \$\begingroup\$ Sure seems like it, I stop flipping opengl's buffer in my render function and the FPS was at 13000+ even when focused. \$\endgroup\$ Jan 10 '13 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .