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

Author Topic: Event Loop Hitches Program  (Read 2702 times)

0 Members and 1 Guest are viewing this topic.

kiaran

  • Newbie
  • *
  • Posts: 17
    • View Profile
Event Loop Hitches Program
« on: May 28, 2009, 07:33:07 am »
When I move my mouse over the SFML window, it stops updating until the mouse stops. I tried taking everything out of the event loop thinking maybe processing an event was causing the hitch:

Code:
Code: [Select]
sf::Event Event;
while (window.GetEvent(Event))
{
//NOTHING IN HERE!!
}



So I removed the event loop entirely and the hitches disappear!! With no event loop, the program runs smoothly. Obviously, I need to keep my event loop so this is not a solution.

I had this exact problem with SDL, which is part of the reason I decided to try SFML. So far I am really liking this library but this bug is torturing me.

kiaran

  • Newbie
  • *
  • Posts: 17
    • View Profile
Event Loop Hitches Program
« Reply #1 on: May 28, 2009, 07:35:34 am »
The event loop ONLY hitches my program while the mouse is moving across the SFML window. So I put a counter in the event loop and moved my mouse a bit to observe how many events were being created each frame due to the mouse.

Code: [Select]
int numEvents=0;

sf::Event Event;
while (window.GetEvent(Event))
{
numEvents++;
}

cout << numEvents << endl;



And my output looks like this:


Code: [Select]
0
0
3 //tapped my mouse
0
0
0
13 //moved my mouse
0
0
0
0
0
222 //moved my mouse for 2 seconds


So it's just accumulating events as long as my mouse is moving. What I really want is for it to just register one event per frame. Either the mouse moved or it didn't.

Why is this accumulating and hitching my program?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Event Loop Hitches Program
« Reply #2 on: May 29, 2009, 09:43:13 pm »
Quote from: "kiaran"
What I really want is for it to just register one event per frame. Either the mouse moved or it didn't.
The program seems to do exactly this. Or which amount of events do you expect from moving your mouse for two seconds?

Probably your framerate is too high. Did you limit it somehow? In spite of that, the extent of performance loss confuses me, as event handling is rarely a real bottleneck... Could you post some code of your surrounding main game loop? Or reproduce the error in a minimal example?

P.S. You are running in release mode, aren't you?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kiaran

  • Newbie
  • *
  • Posts: 17
    • View Profile
Event Loop Hitches Program
« Reply #3 on: May 30, 2009, 12:18:21 am »
Quote
The program seems to do exactly this. Or which amount of events do you expect from moving your mouse for two seconds?


The output stream from my previous post shows the number of events processed on each frame. If the mouse moved during that frame, I would expect to see a '1' printed out not 13 or 222.

As long as I keep moving my mouse, events continue to be accumulating in the event queue and the program STOPS COMPLETELY until the mouse stops generating new events (ie. I take my hand off it).

The behavior I would expect is that as I move the mouse, on each frame a new single event is created and the program moves onward. As it is now, I can effectively pause my program indefinitely by continually moving my mouse around the screen. Oddly enough, I have the same problem with SDL on my machine only the events stop queue up at a certain limit and the program moves on resulting in intermittent stop/go/stop behavior while the mouse is moving.

I will reproduce the bug with minimal code and post it this weekend. Thanks! :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Event Loop Hitches Program
« Reply #4 on: May 30, 2009, 12:38:33 am »
Ah sorry, I misunderstood you. 222 events each frame is too much, I agree. :)

It's strange the same behaviour occurs with SDL. Have you got the possibility to test the code on another computer?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything