We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5238 - SDL_SetRelativeMouseMode closes application on Wayland
Summary: SDL_SetRelativeMouseMode closes application on Wayland
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-18 00:59 UTC by M Stoeckl
Modified: 2020-12-22 22:49 UTC (History)
0 users

See Also:


Attachments
Test program; runs until keypress (or until SDL_RelativeMouseMode called) (1.31 KB, text/x-csrc)
2020-07-18 01:01 UTC, M Stoeckl
Details
Test program output, with env WAYLAND_DEBUG=1 (28.73 KB, text/plain)
2020-07-18 01:01 UTC, M Stoeckl
Details
Interactive version of test program with two windows (3.07 KB, text/x-csrc)
2020-07-31 02:09 UTC, M Stoeckl
Details
Patch: do not simultaneously lock and confine pointer (5.29 KB, patch)
2020-07-31 02:14 UTC, M Stoeckl
Details | Diff
Patch #2: wayland, Clean up dangling pointers when destroying window (4.10 KB, patch)
2020-08-02 22:38 UTC, M Stoeckl
Details | Diff
Interactive version of test program (5.34 KB, text/x-csrc)
2020-08-02 22:40 UTC, M Stoeckl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description M Stoeckl 2020-07-18 00:59:41 UTC
Applications running with the Wayland backend that call SDL_SetRelativeMouseMode(1) will create a protocol violation (trying to both lock a pointer to a position and confine a pointer to a region), making compositors close the application. As documented at https://github.com/wayland-project/wayland-protocols/blob/master/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml#L59-L63, an application may only lock/confine once per surface.

This issue occurs with recent SDL from the default branch of HG, possibly since rev 13805: https://hg.libsdl.org/SDL/rev/4709c1dfeabb .

See attached `pointer_bug.c` for a test case that should work fine on X11, but fails on Wayland. I've tested with Weston, and have attached a log of the Wayland protocol messages from an example run.
Comment 1 M Stoeckl 2020-07-18 01:01:27 UTC
Created attachment 4420 [details]
Test program; runs until keypress (or until SDL_RelativeMouseMode called)
Comment 2 M Stoeckl 2020-07-18 01:01:59 UTC
Created attachment 4421 [details]
Test program output, with env WAYLAND_DEBUG=1
Comment 3 M Stoeckl 2020-07-31 02:09:38 UTC
Created attachment 4429 [details]
Interactive version of test program with two windows
Comment 4 M Stoeckl 2020-07-31 02:14:27 UTC
Created attachment 4430 [details]
Patch: do not simultaneously lock and confine pointer
Comment 5 M Stoeckl 2020-07-31 02:24:32 UTC
I've attached a patch that possibly fixes this issue, by keeping the pointer confinement disabled (not created) as long as there is a conflicting pointer lock.

In the process of creating the patch, I discovered that SDL_WaylandInput::pointer_focus and SDL_WaylandInput::keyboard_focus are never explicitly cleaned up by the Wayland backend. I don't have enough time right now to track down whether or not SDL_video.c guarantees that these are cleared before the object in memory being pointed to is destroyed. In the patch, I introduced a similar variable SDL_WaylandInput::confined_window, about whose cleanup I am similarly uncertain. See also the TODO comment.
Comment 6 M Stoeckl 2020-08-02 22:38:19 UTC
Created attachment 4432 [details]
Patch #2: wayland, Clean up dangling pointers when destroying window
Comment 7 M Stoeckl 2020-08-02 22:40:52 UTC
Created attachment 4433 [details]
Interactive version of test program
Comment 8 M Stoeckl 2020-08-02 22:45:19 UTC
OK, Patch #2 now fixes the TODO comment.
Comment 9 M Stoeckl 2020-12-22 22:49:17 UTC
Fixed as of 2.0.14.