SDL: SDL_GL_SwapWindow() returns an error code

From 88630b85f5c0671f80eb326bfa268f60d3e57a71 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Thu, 29 Dec 2022 16:27:42 +0100
Subject: [PATCH] SDL_GL_SwapWindow() returns an error code

---
 docs/README-migration.md                | 2 ++
 include/SDL3/SDL_video.h                | 5 ++++-
 src/dynapi/SDL_dynapi_procs.h           | 2 +-
 src/render/opengl/SDL_render_gl.c       | 4 ++--
 src/render/opengles2/SDL_render_gles2.c | 4 ++--
 src/video/SDL_sysvideo.h                | 2 --
 src/video/SDL_video.c                   | 7 +------
 7 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index 8ef2630b012e..0991f7f1b8d3 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -827,6 +827,8 @@ Programs which have access to shaders can implement more robust versions of thos
 Removed 'SDL_GL_CONTEXT_EGL' from OpenGL configuration attributes
 You can instead use 'SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);'
 
+'SDL_GL_SwapWindow()' returns an error code.
+
 SDL_VideoInit() and SDL_VideoQuit() have been removed. Instead you can call SDL_InitSubSytem() and SDL_QuitSubSytem() with SDL_INIT_VIDEO, which will properly refcount the subsystems. You can choose a specific audio driver using SDL_VIDEO_DRIVER hint.
 
 'SDL_WINDOW_SHOW' flag has been removed. It's activated by default, and can be unactivated by using SDL_WINDOW_HIDDEN
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index 8bc260e0586d..2f43e1728289 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -2013,9 +2013,12 @@ extern DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(void);
  *
  * \param window the window to change
  *
+ * \returns 0 on success or a negative error code on failure; call
+ *          SDL_GetError() for more information.
+ *
  * \since This function is available since SDL 3.0.0.
  */
-extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window * window);
+extern DECLSPEC int SDLCALL SDL_GL_SwapWindow(SDL_Window * window);
 
 /**
  * Delete an OpenGL context.
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 8eb13994bca6..4baf939b6156 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -230,7 +230,7 @@ SDL_DYNAPI_PROC(int,SDL_GL_MakeCurrent,(SDL_Window *a, SDL_GLContext b),(a,b),re
 SDL_DYNAPI_PROC(void,SDL_GL_ResetAttributes,(void),(),)
 SDL_DYNAPI_PROC(int,SDL_GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_GL_SetSwapInterval,(int a),(a),return)
-SDL_DYNAPI_PROC(void,SDL_GL_SwapWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_GL_SwapWindow,(SDL_Window *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_GL_UnbindTexture,(SDL_Texture *a),(a),return)
 SDL_DYNAPI_PROC(void,SDL_GL_UnloadLibrary,(void),(),)
 SDL_DYNAPI_PROC(SDL_GUID,SDL_GUIDFromString,(const char *a),(a),return)
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index d2116dea99b7..5fcad4a55553 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -21,7 +21,7 @@
 #include "SDL_internal.h"
 
 #if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
-#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult and SDL_RecreateWindow */
+#include "../../video/SDL_sysvideo.h" /* For SDL_RecreateWindow */
 #include <SDL3/SDL_opengl.h>
 #include "../SDL_sysrender.h"
 #include "SDL_shaders_gl.h"
@@ -1480,7 +1480,7 @@ static int GL_RenderPresent(SDL_Renderer *renderer)
 {
     GL_ActivateRenderer(renderer);
 
-    return SDL_GL_SwapWindowWithResult(renderer->window);
+    return SDL_GL_SwapWindow(renderer->window);
 }
 
 static void GL_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 03cd31468137..312d97487050 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -22,7 +22,7 @@
 
 #if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
 
-#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult and SDL_RecreateWindow */
+#include "../../video/SDL_sysvideo.h" /* For SDL_RecreateWindow */
 #include <SDL3/SDL_opengles2.h>
 #include "../SDL_sysrender.h"
 #include "../../video/SDL_blit.h"
@@ -1956,7 +1956,7 @@ static int GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
 static int GLES2_RenderPresent(SDL_Renderer *renderer)
 {
     /* Tell the video driver to swap buffers */
-    return SDL_GL_SwapWindowWithResult(renderer->window);
+    return SDL_GL_SwapWindow(renderer->window);
 }
 
 static int GLES2_SetVSync(SDL_Renderer *renderer, const int vsync)
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index dc96350f404f..50e86a2de6d3 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -515,6 +515,4 @@ extern void SDL_ToggleDragAndDropSupport(void);
 
 extern int SDL_GetDisplayIndexForPoint(const SDL_Point *point);
 
-extern int SDL_GL_SwapWindowWithResult(SDL_Window *window);
-
 #endif /* SDL_sysvideo_h_ */
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 98ab8ec6eb3c..3e2ccfc94159 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -4066,7 +4066,7 @@ int SDL_GL_GetSwapInterval(void)
     }
 }
 
-int SDL_GL_SwapWindowWithResult(SDL_Window *window)
+int SDL_GL_SwapWindow(SDL_Window *window)
 {
     CHECK_WINDOW_MAGIC(window, -1);
 
@@ -4081,11 +4081,6 @@ int SDL_GL_SwapWindowWithResult(SDL_Window *window)
     return _this->GL_SwapWindow(_this, window);
 }
 
-void SDL_GL_SwapWindow(SDL_Window *window)
-{
-    SDL_GL_SwapWindowWithResult(window);
-}
-
 void SDL_GL_DeleteContext(SDL_GLContext context)
 {
     if (_this == NULL || !context) {