Commit 331859079674465a39b24f32a6a113959601dca3

Antoine Fontaine 2022-03-09T17:02:32

Fix relative mouse input for Unvanquished (unvanquished.net) Here's an IRC dump that hopefully explains the issue this fixes: > I'm debugging something odd where, for a libre game, unvanquished.net (a FPS), relative mouse input in fullscreen is buggy > it's like, working mostly ok, but it has a weird performance/cleanup bug > after some time in relative mouse input mode, some time as low as 15s, usually more, the SDL sends A LOT of relative mouse input per frame > almost all of which have xrel==0 && yrel==0 > by A LOT, I mean that after ~1min, it's usually in the thousands per frame > each frame, a while ( SDL_PollEvent( &e)) loop reads the inputs, but it seems SDL is not clearing the list. > one way to clear the list is to open the in-game console or menu, which switches the input mode to absolute, then close it which gets a working relative input mode (for some time at least) > I've shown the issue to be present with SDL2.0.20 but not with 2.0.14 on my system > some other players on Arch Linux (SDL2.0.20) report a possibly related issue, where some keys seem to be pressed at random > I've did some bisection on SDL master, and I've found that there are actually two commits involved, one breaking it totally (no input at all), and one fixing it partially (with the problem described above) First related commit that breaks it totally: commit 82793ac279d19b5bde8fc2bd62877b05ba5a76e0 Author: Sam Lantinga <slouken@libsdl.org> Date: Thu Oct 14 14:26:21 2021 -0700 Fixed mouse warping while in relative mode We should get a mouse event with an absolute position and no relative motion and shouldn't change the OS cursor position at all Second related commit, that halfway fixes it: commit 31f8c3ef4409a93fafa894b78c2ce176bd0c3cf3 Author: Sam Lantinga <slouken@libsdl.org> Date: Thu Jan 6 11:27:44 2022 -0800 Fixed event pump starvation if the application frequently pushes its own events Reverting the first commit did fix the issue for me, but would probably reintroduce the bug it was fixing(?). This patch should fix it for everyone hopefully. https://github.com/DaemonEngine/Daemon/issues/600 is the upstream bug, and contains some early investigation.

1
2
3
4
5
6
7
8
9
10
11
12
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index a30c3db..3a9b7a8 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -383,6 +383,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
         mouse->x = x;
         mouse->y = y;
         mouse->has_position = SDL_TRUE;
+        return 0;
     } else if (!xrel && !yrel) {  /* Drop events that don't change state */
 #ifdef DEBUG_MOUSE
         printf("Mouse event didn't change state - dropped!\n");