SFML community forums
Help => Graphics => Topic started by: chris67 on January 06, 2010, 08:50:57 pm
-
This is a total game breaker for me unless I am missing something huge here.
The problem is when I add GetEvent(Event) in my code it slows or even STOPS my program when I move the mouse around.
I display the fps and even added a counter to increment each time the program loops and they both stop dead when I move the mouse.
I have been puzzling over this for quite a while and I cannot find anything on the forum about it.
Here is my code, someone else please run it and see if you get the same results:
#include <SFML/Graphics.hpp>
int main()
{
sf::Font MyFont;
sf::String fps;
sf::String counter;
char buffer[200];
int num = 0;
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");
if (!MyFont.LoadFromFile("font/small/XPAIDERP.TTF", 8))
return EXIT_FAILURE;
fps.SetFont(MyFont);
fps.SetSize(8);
fps.SetPosition(100.f, 100.f);
counter.SetFont(MyFont);
counter.SetSize(8);
counter.SetPosition(100.f, 200.f);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
sprintf( buffer, "FPS = %f", 100.f / App.GetFrameTime() );
fps.SetText( buffer );
App.Draw( fps );
sprintf( buffer, "COUNTER = %d", num );
counter.SetText( buffer );
App.Draw( counter );
App.Display();
num++;
}
return EXIT_SUCCESS;
}
I move the mouse around and both the counter and the fps freeze. This can only mean the program itself is freezing. If I comment out while (App.GetEvent(Event)) then everything goes smoothly and I can move the mouse around with no freezing.
System:
WindowsXP service pack 3
DirectX 9.0c
AMD athlon 2.21 GHZ
2 GB RAM
Using Code::blocks IDE with MingW
-
Your program ran fine for me (after commenting out the font stuff).
-
Maybe you receive a huge amount of unexpected events. Can you add some logs in your event loop to know what is received exactly?
-
Maybe you receive a huge amount of unexpected events. Can you add some logs in your event loop to know what is received exactly?
Ok here is what I did. I added a counter to the event loop to increment each time there is an event. Then I displayed the counter on screen to see how many times the event loop was running.
The result was that the event looped maybe 3 times when I moved the mouse cursor a small distance. However this was still freezing both the fps and the main program loop counter. So for some reason App.GetEvent(Event) is running hella slow on my system.
Here is the new code:
#include <SFML/Graphics.hpp>
int main()
{
sf::Font MyFont;
sf::String fps;
sf::String counter;
sf::String EventCount;
char buffer[200];
int num = 0;
int evnum = 0;
// Create the main window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");
if (!MyFont.LoadFromFile("font/small/XPAIDERP.TTF", 8))
return EXIT_FAILURE;
fps.SetFont(MyFont);
fps.SetSize(8);
fps.SetPosition(100.f, 100.f);
counter.SetFont(MyFont);
counter.SetSize(8);
counter.SetPosition(100.f, 200.f);
EventCount.SetFont(MyFont);
EventCount.SetSize(8);
EventCount.SetPosition(100.f, 300.f);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if( Event.Type == sf::Event::Closed )
App.Close();
evnum++;
}
App.Clear();
sprintf( buffer, "FPS = %f", 100.f / App.GetFrameTime() );
fps.SetText( buffer );
App.Draw( fps );
sprintf( buffer, "COUNTER = %d", num );
counter.SetText( buffer );
App.Draw( counter );
sprintf( buffer, "EVENTS = %d", evnum );
EventCount.SetText( buffer );
App.Draw( EventCount );
App.Display();
num++;
}
return EXIT_SUCCESS;
}
I am using sfml version 1.5
-
Did you try the samples provided in the SFML SDK?
-
Did you try the samples provided in the SFML SDK?
Yep, just ran pong and same problem. When I move the mouse the ball freezes.
Same thing with opengl, the rotating cube freezes.
-
What happens when you stop moving the mouse? Does the program run smoothly again, or does it stay frozen?
-
What happens when you stop moving the mouse? Does the program run smoothly again, or does it stay frozen?
It starts running smoothly again.
The mouse movement makes the most visible effect, but it also gets choppy when I hold down a key on the keyboard.
-
How many events do you have when you press a single key?
-
How many events do you have when you press a single key?
I go through the event loop twice. Looks like one for the press and one for the release.
-
Yes, it looks ok :?
-
use a log file or something other than sf::strings to see if it has something to do with that.
-
use a log file or something other than sf::strings to see if it has something to do with that.
It has nothing to do with sf::strings.
If I comment out the event loop everything runs smoothly.
-
Have you tried switching between static and dynamic libraries? Debug and release?
-
I ran it again and everything is running smoothly now. I have no idea why :?
Yesterday I installed Visual C++ 2008 express. Then I uninstalled microsoft presentation foundation, which I think came with VC++ 2008 express.
Those are the only things I remember doing between the time it wasn't working and now.
Very strange.
-
I have had similar issues during the past two months or so, sometimes it will freeze whenever I move the mouse cursor (GetEvent), and it won't go away until I restart my computer. Most of the time it works fine, though.
-
I have had similar issues during the past two months or so, sometimes it will freeze whenever I move the mouse cursor (GetEvent), and it won't go away until I restart my computer. Most of the time it works fine, though.
Ah yes, that was something else I did, I restarted my computer. Still, every other application ran fine, so it was something specifically to do with SFML.
Just happened again in fact. My computer had been running for a day or two, and I started one of the samples ( the box one ) and same thing, mouse movement slowed down the rotating cube. I reset my computer and it was all smooth again.
-
I have the same problem. No idea how to fix it (1.6 here)
-
Check the task manager and see what the memory usage is when this happens. It may be a memory leak if so some debugging is in order.
Laurent, maybe you should check the Mouse event functions in the SDK and make sure you have no stray loops.
-
I've had similar problem but I just solved it with a for-loop instead
for (int i = 0 ; (i < 3) && (app.GetEvent(event) ; i++) {
//handle events
}