SDL: wayland: Clean up xdg_dialog objects with toplevel windows

From 05c5b3398f73195e22c6f01f90bf6fc223e35561 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 1 May 2024 15:18:23 -0400
Subject: [PATCH] wayland: Clean up xdg_dialog objects with toplevel windows

---
 src/video/wayland/SDL_waylandwindow.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 83dc22a258de6..736d09c1a4c49 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -1858,6 +1858,11 @@ void Wayland_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
         SDL_SetStringProperty(props, SDL_PROP_WINDOW_WAYLAND_XDG_TOPLEVEL_EXPORT_HANDLE_STRING, NULL);
     }
 
+    if (wind->xdg_dialog_v1) {
+        xdg_dialog_v1_destroy(wind->xdg_dialog_v1);
+        wind->xdg_dialog_v1 = NULL;
+    }
+
 #ifdef HAVE_LIBDECOR_H
     if (wind->shell_surface_type == WAYLAND_SURFACE_LIBDECOR) {
         if (wind->shell_surface.libdecor.frame) {
@@ -2618,10 +2623,6 @@ void Wayland_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
             wp_fractional_scale_v1_destroy(wind->fractional_scale);
         }
 
-        if (wind->xdg_dialog_v1) {
-            xdg_dialog_v1_destroy(wind->xdg_dialog_v1);
-        }
-
         SDL_free(wind->outputs);
         SDL_free(wind->app_id);