SDL: wayland: Don't store wl_output pointers in mode driver data

From f9ba0e1dbdf7cb5d3ff82d1c26f62025ca7093fc Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 14 Feb 2024 10:27:42 -0500
Subject: [PATCH] wayland: Don't store wl_output pointers in mode driver data

They aren't used for anything, and cause problems if the video core tries to free them.
---
 src/video/wayland/SDL_waylandvideo.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index d443d05f70e9..0ba46f43e18e 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -647,7 +647,6 @@ static void AddEmulatedModes(SDL_DisplayData *dispdata, int native_width, int na
         SDL_zero(mode);
         mode.format = dpy->desktop_mode.format;
         mode.refresh_rate = dpy->desktop_mode.refresh_rate;
-        mode.driverdata = dpy->desktop_mode.driverdata;
 
         if (rot_90) {
             mode.w = mode_list[i].h;
@@ -773,16 +772,8 @@ static void display_handle_done(void *data,
     }
 
     /* If the display was already created, reset and rebuild the mode list. */
-    if (driverdata->display != 0) {
-        int i;
-        dpy = SDL_GetVideoDisplay(driverdata->display);
-
-        /* Clear the wl_output ref so Reset doesn't free it */
-        for (i = 0; i < dpy->num_fullscreen_modes; ++i) {
-            dpy->fullscreen_modes[i].driverdata = NULL;
-        }
-
-        /* Okay, now it's safe to reset */
+    dpy = SDL_GetVideoDisplay(driverdata->display);
+    if (dpy) {
         SDL_ResetFullscreenDisplayModes(dpy);
     }
 
@@ -799,7 +790,6 @@ static void display_handle_done(void *data,
         native_mode.h = driverdata->pixel_height;
     }
     native_mode.refresh_rate = ((100 * driverdata->refresh) / 1000) / 100.0f; /* mHz to Hz */
-    native_mode.driverdata = driverdata->output;
 
     if (driverdata->has_logical_size) { /* If xdg-output is present... */
         if (native_mode.w != driverdata->screen_width || native_mode.h != driverdata->screen_height) {
@@ -835,7 +825,6 @@ static void display_handle_done(void *data,
     desktop_mode.h = driverdata->screen_height;
     desktop_mode.pixel_density = driverdata->scale_factor;
     desktop_mode.refresh_rate = ((100 * driverdata->refresh) / 1000) / 100.0f; /* mHz to Hz */
-    desktop_mode.driverdata = driverdata->output;
 
     if (driverdata->display > 0) {
         dpy = SDL_GetVideoDisplay(driverdata->display);
@@ -957,7 +946,6 @@ static void Wayland_free_display(SDL_VideoDisplay *display)
 {
     if (display) {
         SDL_DisplayData *display_data = display->driverdata;
-        int i;
 
         SDL_free(display_data->wl_output_name);
 
@@ -974,11 +962,6 @@ static void Wayland_free_display(SDL_VideoDisplay *display)
         /* Unlink this display. */
         WAYLAND_wl_list_remove(&display_data->link);
 
-        /* Null the driverdata member of the mode structs, or they will be wrongly freed. */
-        for (i = display->num_fullscreen_modes; i--;) {
-            display->fullscreen_modes[i].driverdata = NULL;
-        }
-        display->desktop_mode.driverdata = NULL;
         SDL_DelVideoDisplay(display->id, SDL_FALSE);
     }
 }