Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
X11 implementation sometimes fails to process keyRelease events. #404
When SFML's key repeat is enabled on X11, WindowImplX11 sometimes doesn't process key released events. This seems to be because it erroneously discards them when trying to filter repeated events.
This causes the game to think a key is held down when in reality the key is released.
How To Reproduce
Hold a key down long enough to cause the OS to send key repeat events, and then release it. It's more likely to happen when your OS has a high key refresh set. Sometimes SFML will report the key as pressed when it's actually released.
Replace 'examples/window/Window.cpp' and 'src/SFML/Window/Linux/WindowImplX11.cpp' with the files in this gist: https://gist.github.com/citizen-erased/5745591
I added some print statements to the window example and X11 implementation to show the issue. You can see it discards the final key up event from X11 (duplicate=1, discard=1) and SFML reports the key as pressed (down=1). The lines of dashes separate iterations of the main loop.
Increasing the key repeat rate increases the chance of the issue happening. It happened maybe 5 - 10% of the time with the following settings. In a shell:
xset r rate 170 50
Note: This can also be reproduced at a lesser frequency with a more normal repeat rate.
What I don't understand is, how can you trigger two real events (key down and key up) with the exact same timestamp? Only repeated (fake) events are supposed to behave this way, if a human presses a key it will most likely last at least a few milliseconds before he releases it.
And can you do the same test with SDL? the hack I use in SFML is inspired by it, so it would be interesting to see if the hack itself is not reliable, or if it's only my implementation.
Laurent Gomila firstname.lastname@example.org skrev:
The output I posted only shows the last few iterations of the main loop. The real up and down events are seconds apart. The final X11 event, with a time different of 0, must be the real release event as it's preceded by the up and down event pair which is the OS sending key repeats.
Is it possible the real key up event occurs at the same time as the repeat events (at least according to the timer being used)?
I was unable to reproduce it with the latest version of SDL. I tried my SDL example on a different computer and was successfully able to reproduce it, so hopefully that rules out my hardware setup.
So SDL has the same bug? Or did you mean "SFML" in your last sentence?