From eb3fc0684c9957de108df5b338307418b0130c3b Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sun, 15 Dec 2024 10:44:31 -0500
Subject: [PATCH] wayland: Don't close an externally owned display on init
failure
---
src/video/wayland/SDL_waylandvideo.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 7a6fda36645f5..b778f9b29d0e2 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -525,14 +525,18 @@ static SDL_VideoDevice *Wayland_CreateDevice(bool require_preferred_protocols)
* and frame-pacing by default due to swapchain starvation.
*/
if (require_preferred_protocols && !Wayland_IsPreferred(display)) {
- WAYLAND_wl_display_disconnect(display);
+ if (!display_is_external) {
+ WAYLAND_wl_display_disconnect(display);
+ }
SDL_WAYLAND_UnloadSymbols();
return NULL;
}
data = SDL_calloc(1, sizeof(*data));
if (!data) {
- WAYLAND_wl_display_disconnect(display);
+ if (!display_is_external) {
+ WAYLAND_wl_display_disconnect(display);
+ }
SDL_WAYLAND_UnloadSymbols();
return NULL;
}
@@ -540,7 +544,9 @@ static SDL_VideoDevice *Wayland_CreateDevice(bool require_preferred_protocols)
input = SDL_calloc(1, sizeof(*input));
if (!input) {
SDL_free(data);
- WAYLAND_wl_display_disconnect(display);
+ if (!display_is_external) {
+ WAYLAND_wl_display_disconnect(display);
+ }
SDL_WAYLAND_UnloadSymbols();
return NULL;
}
@@ -562,7 +568,9 @@ static SDL_VideoDevice *Wayland_CreateDevice(bool require_preferred_protocols)
if (!device) {
SDL_free(input);
SDL_free(data);
- WAYLAND_wl_display_disconnect(display);
+ if (!display_is_external) {
+ WAYLAND_wl_display_disconnect(display);
+ }
SDL_WAYLAND_UnloadSymbols();
return NULL;
}