Commit dad8df3ed1e6397e6ad97215921322f5ed6a70b4

pionere 2022-11-14T08:20:31

video: check graphics flags the same way in SDL_RecreateWindow as in SDL_CreateWindow - single check to validate the graphics flags - check it before tearing down the window

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 1945860..51e282f 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1874,6 +1874,13 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
     SDL_bool loaded_vulkan = SDL_FALSE;
     SDL_bool need_vulkan_unload = SDL_FALSE;
     SDL_bool need_vulkan_load = SDL_FALSE;
+    Uint32 graphics_flags;
+
+    /* ensure no more than one of these flags is set */
+    graphics_flags = flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_METAL | SDL_WINDOW_VULKAN);
+    if ((graphics_flags & (graphics_flags - 1)) != 0) {
+        return SDL_SetError("Conflicting window flags specified");
+    }
 
     if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
         return SDL_ContextNotSupported("OpenGL");
@@ -1937,18 +1944,6 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
         need_vulkan_load  = SDL_TRUE;
     }
 
-    if ((flags & SDL_WINDOW_VULKAN) && (flags & SDL_WINDOW_OPENGL)) {
-        return SDL_SetError("Vulkan and OpenGL not supported on same window");
-    }
-
-    if ((flags & SDL_WINDOW_METAL) && (flags & SDL_WINDOW_OPENGL)) {
-        return SDL_SetError("Metal and OpenGL not supported on same window");
-    }
-
-    if ((flags & SDL_WINDOW_METAL) && (flags & SDL_WINDOW_VULKAN)) {
-        return SDL_SetError("Metal and Vulkan not supported on same window");
-    }
-
     if (need_gl_unload) {
         SDL_GL_UnloadLibrary();
     }