Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML using 3-2 times as much CPU when hidden behind another window?  (Read 2705 times)

0 Members and 1 Guest are viewing this topic.

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
I'm running on a Mac and compiled my project using MonoD with D-SFML.

When I have my window completely hidden behind another window, CPU usage goes from 10% to 30%. I noticed it because my laptop's fans started whirring. If the window is slightly visible, CPU is 10%. As soon as I make the window completely not visible, it goes to 30% CPU usage.

It's not a serious problem but it is making my curious. Why does this happen?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML using 3-2 times as much CPU when hidden behind another window?
« Reply #1 on: January 27, 2015, 10:26:25 am »
Do you limit your framerate?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: SFML using 3-2 times as much CPU when hidden behind another window?
« Reply #2 on: January 27, 2015, 04:58:18 pm »
No. I have it set up like the example program. A while loop for when the window is open. In that while loop I handle events, logic and drawing the window.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: SFML using 3-2 times as much CPU when hidden behind another window?
« Reply #3 on: January 27, 2015, 05:22:41 pm »
What is probably happening is that the drawing is optimised out; then your program is no longer waiting (i.e. idle) on the display() call but instead is working on something.
SFML / OS X developer

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: SFML using 3-2 times as much CPU when hidden behind another window?
« Reply #4 on: January 27, 2015, 07:16:55 pm »
Oh. So I should make the thread sleep if it's going faster than 60fps?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
SFML / OS X developer

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: SFML using 3-2 times as much CPU when hidden behind another window?
« Reply #6 on: January 27, 2015, 08:13:19 pm »
Yay that fixed it.  :D