-
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 ;)
-
You have to limit framerate.
You can use setFramerateLimit (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#af4322d315baf93405bf0d5087ad5e784) or setVerticalSyncEnabled (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#a59041c4556e0351048f8aff366034f61).
-
Nothing changed! Cpu usage is as high as before!
-
What code did you add exactly ?
-
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 ;)
-
You did it well.
I don't understand why you still have this issue.
I hope someone else can help.
-
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?
-
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).
-
@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/ (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.
-
Sounds an awful lot like this post (http://en.sfml-dev.org/forums/index.php?topic=9481.0)...
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.
-
If you want to prevent it
We still don't know if it's that ;)
-
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:
(https://legacy.sfmluploads.org/cache/pics/277_joy.png)
The question now is just why does it get called so often?
-
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 ???
-
In which file is the window::pollEvent and what are cmakelist.txt files.
I have no clue how to compile sfml ;D
-
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).
what are cmakelist.txt files.
I have no clue how to compile sfml
That's why I've written a tutorial for that ;)
-
I can“t find Joystick::update in window.cpp and WindowImpl.cpp.
Should i comment out something different?
-
Sorry, it's
JoystickManager::getInstance().update();
at line 148 of WindowImpl.cpp.
-
Now everything runs fine i have 2% Cpu usage :)
Thank you
-
By the way, did you have this problem with SFML 2.0 RC or with the latest sources?
-
With the Rc and the latest source!
-
Strange, I solved this problem after the RC :-\
-
It was LaurentGomila-SFML-2.0-rc-97-g109d914.tar
-
Tried to reproduce this out of interest, but couldn't get it to
work bug out.
I've got a Logitech Mouse (no drivers) and a Logitech Keyboard (with Logitech drivers), but CPU load sticks to 0% with or without an Xbox360 controller connected.
-
It was LaurentGomila-SFML-2.0-rc-97-g109d914.tar
I don't remember all commit hashes :P
From when is it?
-
I downloaded it on friday a few hours after i created this thread.
-
Ok, thanks.