video: check graphics flags the same way as the type flags
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index fdfd912..1945860 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1597,7 +1597,7 @@ SDL_Window *
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{
SDL_Window *window;
- Uint32 type_flags, graphics_flags = flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_METAL | SDL_WINDOW_VULKAN);
+ Uint32 type_flags, graphics_flags;
if (!_this) {
/* Initialize the video system if needed */
@@ -1627,6 +1627,13 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
return NULL;
}
+ /* 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) {
+ SDL_SetError("Conflicting window flags specified");
+ return NULL;
+ }
+
/* Some platforms have certain graphics backends enabled by default */
if (!graphics_flags && !SDL_IsVideoContextExternal()) {
#if (SDL_VIDEO_OPENGL && __MACOSX__) || (__IPHONEOS__ && !TARGET_OS_MACCATALYST) || __ANDROID__ || __NACL__
@@ -1656,10 +1663,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
SDL_ContextNotSupported("Vulkan");
return NULL;
}
- if (graphics_flags & SDL_WINDOW_OPENGL) {
- SDL_SetError("Vulkan and OpenGL not supported on same window");
- return NULL;
- }
if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
return NULL;
}
@@ -1670,16 +1673,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
SDL_ContextNotSupported("Metal");
return NULL;
}
- /* 'flags' may have default flags appended, don't check against that. */
- if (graphics_flags & SDL_WINDOW_OPENGL) {
- SDL_SetError("Metal and OpenGL not supported on same window");
- return NULL;
- }
- if (graphics_flags & SDL_WINDOW_VULKAN) {
- SDL_SetError("Metal and Vulkan not supported on same window. "
- "To use MoltenVK, set SDL_WINDOW_VULKAN only.");
- return NULL;
- }
}
/* Unless the user has specified the high-DPI disabling hint, respect the