SDL: Added macros to push/pop error messages while cleaning up (abbaf)

From abbaf95cf0614db04221e60349467cdf9e941e73 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 29 May 2025 10:53:46 -0700
Subject: [PATCH] Added macros to push/pop error messages while cleaning up

(cherry picked from commit 885e611f3c2f65051bb639defe398e3a1a186eb4)
---
 src/SDL_internal.h    | 6 ++++++
 src/video/SDL_video.c | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index a345252f3a115..8fcd96a7fa97d 100644
--- a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -265,6 +265,12 @@ extern "C" {
 #include "SDL_utils_c.h"
 #include "SDL_hashtable.h"
 
+#define PUSH_SDL_ERROR() \
+    { char *_error = SDL_strdup(SDL_GetError());
+
+#define POP_SDL_ERROR() \
+    SDL_SetError("%s", _error); SDL_free(_error); }
+
 // Do any initialization that needs to happen before threads are started
 extern void SDL_InitMainThread(void);
 
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index d3774788fc99c..db38a19d0d04e 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -2513,7 +2513,9 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props)
     SDL_UpdateWindowHierarchy(window, parent);
 
     if (_this->CreateSDLWindow && !_this->CreateSDLWindow(_this, window, props)) {
+        PUSH_SDL_ERROR()
         SDL_DestroyWindow(window);
+        POP_SDL_ERROR()
         return NULL;
     }