Skip to content

Commit 01075dc

Browse files
committed
Fixed bug 4689 - SDL fails to detect compositor shutdown on Wayland -- program keeps running
M Stoeckl To reproduce: 1. Run any SDL-based program with a Wayland compositor, orphaning it so that it doesn't have an immediate parent process. (For example, from a terminal, running `supertux2 & disown`.) The program should use the wayland backend, i.e. by setting environment variable SDL_VIDEODRIVER=wayland. 2. Kill the compositor process. Results: - The SDL program will keep running. Expected results: - The SDL program should close. (What close should mean here, I'm not sure - is injecting an SDL_Quit the appropriate action when a video driver disconnects?) Build data: 2019-06-22, hg tip (12901:5cbf6472a916), Linux, can reproduce with sway, weston, and other Wayland oompositors.
1 parent 99abe12 commit 01075dc

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/video/wayland/SDL_waylandevents.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,23 @@ void
178178
Wayland_PumpEvents(_THIS)
179179
{
180180
SDL_VideoData *d = _this->driverdata;
181+
int err;
181182

182183
WAYLAND_wl_display_flush(d->display);
183184

184185
if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_FALSE, 0)) {
185-
WAYLAND_wl_display_dispatch(d->display);
186+
err = WAYLAND_wl_display_dispatch(d->display);
187+
} else {
188+
err = WAYLAND_wl_display_dispatch_pending(d->display);
186189
}
187-
else
188-
{
189-
WAYLAND_wl_display_dispatch_pending(d->display);
190+
if (err == -1 && !d->display_disconnected) {
191+
/* Something has failed with the Wayland connection -- for example,
192+
* the compositor may have shut down and closed its end of the socket,
193+
* or there is a library-specific error. No recovery is possible. */
194+
d->display_disconnected = 1;
195+
/* Only send a single quit message, as application shutdown might call
196+
* SDL_PumpEvents */
197+
SDL_SendQuit();
190198
}
191199
}
192200

src/video/wayland/SDL_waylandvideo.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,9 @@ static const struct wl_registry_listener registry_listener = {
412412
int
413413
Wayland_VideoInit(_THIS)
414414
{
415-
SDL_VideoData *data = SDL_malloc(sizeof *data);
415+
SDL_VideoData *data = SDL_calloc(1, sizeof(*data));
416416
if (data == NULL)
417417
return SDL_OutOfMemory();
418-
memset(data, 0, sizeof *data);
419418

420419
_this->driverdata = data;
421420

src/video/wayland/SDL_waylandvideo.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct qt_windowmanager;
4848

4949
typedef struct {
5050
struct wl_display *display;
51+
int display_disconnected;
5152
struct wl_registry *registry;
5253
struct wl_compositor *compositor;
5354
struct wl_shm *shm;

0 commit comments

Comments
 (0)