Browse Source

video: Return an error on failure to set the video mode

If SDL_UpdateFullscreenMode() fails to find a matching mode for the window, it will restore the window to its previous state, but still returns a success code of 0. Return an error code of -1 if no matching display mode can be found.
Frank Praznik 2 years ago
parent
commit
8f8746cc1b
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/video/SDL_video.c

+ 5 - 1
src/video/SDL_video.c

@@ -1324,6 +1324,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
 {
     SDL_VideoDisplay *display;
     SDL_Window *other;
+    int retval = 0;
 
     CHECK_WINDOW_MAGIC(window, -1);
 
@@ -1468,6 +1469,9 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
 
                 window->last_fullscreen_flags = window->flags;
                 return 0;
+            } else {
+                /* Failed to find a matching mode, return an error after restoring windowed mode. */
+                retval = -1;
             }
         }
     }
@@ -1487,7 +1491,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
     SDL_RestoreMousePosition(window);
 
     window->last_fullscreen_flags = window->flags;
-    return 0;
+    return retval;
 }
 
 #define CREATE_FLAGS \