SDL: x11: Remove the "safety net" error handler.

From e61f0678ee6320fb5b9a5d52bffdca35d94f2d6c Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 22 Oct 2024 10:27:36 -0400
Subject: [PATCH] x11: Remove the "safety net" error handler.

This is an X11 error catcher that lived for the entire life of the program,
which causes problems in itself, but it also tries to make calls into Xlib,
which would cause further panics.

It's goal was to reset video modes if the app was going down, but it often
failed to do so, and caused potentially avoidable crashes instead.

Fixes #7975.
---
 src/video/x11/SDL_x11video.c | 34 ----------------------------------
 1 file changed, 34 deletions(-)

diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index 57e51d6740f5c..f5ed6f4fbdaea 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -49,8 +49,6 @@ static void X11_VideoQuit(SDL_VideoDevice *_this);
 
 // X11 driver bootstrap functions
 
-static int (*orig_x11_errhandler)(Display *, XErrorEvent *) = NULL;
-
 static void X11_DeleteDevice(SDL_VideoDevice *device)
 {
     SDL_VideoData *data = device->internal;
@@ -58,7 +56,6 @@ static void X11_DeleteDevice(SDL_VideoDevice *device)
         device->Vulkan_UnloadLibrary(device);
     }
     if (data->display) {
-        X11_XSetErrorHandler(orig_x11_errhandler);
         X11_XCloseDisplay(data->display);
     }
     if (data->request_display) {
@@ -74,33 +71,6 @@ static void X11_DeleteDevice(SDL_VideoDevice *device)
     SDL_X11_UnloadSymbols();
 }
 
-// An error handler to reset the vidmode and then call the default handler.
-static bool safety_net_triggered = false;
-static int X11_SafetyNetErrHandler(Display *d, XErrorEvent *e)
-{
-    SDL_VideoDevice *device = NULL;
-    // if we trigger an error in our error handler, don't try again.
-    if (!safety_net_triggered) {
-        safety_net_triggered = true;
-        device = SDL_GetVideoDevice();
-        if (device) {
-            int i;
-            for (i = 0; i < device->num_displays; i++) {
-                SDL_VideoDisplay *display = device->displays[i];
-                if (SDL_GetCurrentDisplayMode(display->id) != SDL_GetDesktopDisplayMode(display->id)) {
-                    X11_SetDisplayMode(device, display, &display->desktop_mode);
-                }
-            }
-        }
-    }
-
-    if (orig_x11_errhandler) {
-        return orig_x11_errhandler(d, e); // probably terminate.
-    }
-
-    return 0;
-}
-
 static bool X11_IsXWayland(Display *d)
 {
     int opcode, event, error;
@@ -164,10 +134,6 @@ static SDL_VideoDevice *X11_CreateDevice(void)
     X11_XSynchronize(data->display, True);
 #endif
 
-    // Hook up an X11 error handler to recover the desktop resolution.
-    safety_net_triggered = false;
-    orig_x11_errhandler = X11_XSetErrorHandler(X11_SafetyNetErrHandler);
-
     /* Steam Deck will have an on-screen keyboard, so check their environment
      * variable so we can make use of SDL_StartTextInput.
      */