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

Author Topic: High Cpu usage SFML 2.0  (Read 13328 times)

0 Members and 1 Guest are viewing this topic.

nonikel

  • Newbie
  • *
  • Posts: 13
    • View Profile
High Cpu usage SFML 2.0
« on: October 26, 2012, 01:33:30 pm »
Hello,

i have a problem with sfml 2.0!
On my pc and my laptop the cpu usage is very high (Pc: 25% / Laptop: 50%).
When i run the same project with a few changes with sfml 1.6 the cpu usage is normal(Pc: 4% / Laptop: 9%).
Here is the example code for SFML 2.0:
#include <SFML\Graphics.hpp>

void main()
{
        sf::Sprite SPlayer;
        sf::Texture TPlayer;
        sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Test");
        sf::Event Event;
        TPlayer.loadFromFile("test.png");
        SPlayer.setTexture(TPlayer);
        SPlayer.setPosition(500, 500);

        while(App.isOpen())
        {
                while(App.pollEvent(Event))
                {
                        if(Event.type == sf::Event::Closed)
                App.close();
                }

                App.clear();

                App.draw(SPlayer);

                App.display();
        }
}

In sfml 1.6 i use sf::image instead of sf::texture.
On both pc and laptop my os ist windows 7 (pc 64bit and laptop 32bit).
The pc has i5 2500k cpu and gtx 560ti graphics card. The laptop has a core 2 duo t6500 with 2.1 GHz and geforce 9600m gs graphics card.
On both i use visual studio express 2010 and there are no errors or warnings.

I hope someone could help me ;)

kimci86

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #1 on: October 26, 2012, 02:06:11 pm »
You have to limit framerate.
You can use setFramerateLimit or setVerticalSyncEnabled.

nonikel

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #2 on: October 26, 2012, 02:52:49 pm »
Nothing changed! Cpu usage is as high as before!

kimci86

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #3 on: October 26, 2012, 02:56:12 pm »
What code did you add exactly ?

nonikel

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #4 on: October 26, 2012, 02:59:46 pm »
I tested both and i added them before the loop.

App.setVerticalSyncEnabled(true);
and
App.setFramerateLimit(60);

And no i dont used both at the same time ;)

kimci86

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #5 on: October 26, 2012, 03:09:24 pm »
You did it well.
I don't understand why you still have this issue.
I hope someone else can help.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10914
    • View Profile
    • development blog
    • Email
Re: High Cpu usage SFML 2.0
« Reply #6 on: October 26, 2012, 03:20:36 pm »
So if you run the following example you still get a high CPU usage?
#include <SFML/Graphics.hpp>

void main()
{
    sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Test");
    App.setFramerateLimit(60);

    sf::Sprite SPlayer;
    sf::Texture TPlayer;

    TPlayer.loadFromFile("test.png");
    SPlayer.setTexture(TPlayer, true);

    while(App.isOpen())
    {
        sf::Event Event;
        while(App.pollEvent(Event))
        {
            if(Event.type == sf::Event::Closed)
                App.close();
        }

        App.clear();

        App.draw(SPlayer);

        App.display();
    }
}

This isn't expected...
Use a profiler to find out where most of the time is spend.

Do you have some Joystick driver installed or use a very high DPI mouse?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #7 on: October 26, 2012, 03:39:42 pm »
It's also possible your display driver ignores the VSync preset (i.e. VSync is forced to be off).

Try to count the number of frames per second rendered. Then you should be able to see whether it's simply not slowed down or there's some other issue (cause your frame rate is at the expected value or even lower).

nonikel

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #8 on: October 26, 2012, 03:48:58 pm »
@eXpl0it3r
I used Very Sleepy to profile it.
I dont know what it mean but here is a screenshot of it: http://imageshack.us/photo/my-images/803/sleepyr.png/

I have a logitech mx 518 mouse with 800 dpi at default and i have no Joystick.

@Mario
I have tested the framerate with fraps and it shows 60 fps.
Also i have forced VSync at my Nvidea driver.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10914
    • View Profile
    • development blog
    • Email
Re: High Cpu usage SFML 2.0
« Reply #9 on: October 26, 2012, 03:54:21 pm »
Sounds an awful lot like this post...

Might be a newly old bug. If you want to prevent it and don't use a joystick you could "comment out the call to Joystick::update (should be hidden under Window::pollEvent)." and then recompile SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: High Cpu usage SFML 2.0
« Reply #10 on: October 26, 2012, 04:00:03 pm »
Quote
If you want to prevent it
We still don't know if it's that ;)
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10914
    • View Profile
    • development blog
    • Email
Re: High Cpu usage SFML 2.0
« Reply #11 on: October 26, 2012, 04:14:04 pm »
Quote
If you want to prevent it
We still don't know if it's that ;)
Did you take a look at the screenshot?
Here's again the most important part:


The question now is just why does it get called so often?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: High Cpu usage SFML 2.0
« Reply #12 on: October 26, 2012, 04:54:48 pm »
Quote
Did you take a look at the screenshot?
Here's again the most important part
I'm sorry, but... I can't find this screenshot ???
Laurent Gomila - SFML developer

nonikel

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: High Cpu usage SFML 2.0
« Reply #13 on: October 26, 2012, 05:47:31 pm »
In which file is the window::pollEvent and what are cmakelist.txt files.
I have no clue how to compile sfml  ;D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: High Cpu usage SFML 2.0
« Reply #14 on: October 26, 2012, 06:27:50 pm »
Quote
In which file is the window::pollEvent
Window.cpp. But you'll probably need to go one step deeper, in WindowImpl (don't remember the name of the function).

Quote
what are cmakelist.txt files.
I have no clue how to compile sfml
That's why I've written a tutorial for that ;)
Laurent Gomila - SFML developer

 

anything