foxygit / doom Log in
commit 7bb82228db4c9f13f706cde47472619d7044ef85
Author:     Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Tue Mar 28 13:00:38 2017 +0200
Commit:     Fabian Greffrath <fabian@greffrath.com>
CommitDate: Tue Mar 28 13:00:38 2017 +0200

    video: move video_display check to I_GetWindowPosition()

    This way make sure that the video_display variable is checked (1)
    unconditionally and (2) early on in the code before other parts of the
    video initialization path use it.

    Formerly, the check was in CenterWindow() which was only called from
    I_GetWindowPosition() if fullscreen was enabled or the window was
    centered.

    Fixes #898 thanks @jmtd
---
 src/i_video.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index 18551c40..d26fbcab 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1082,17 +1082,6 @@ static void CenterWindow(int *x, int *y, int w, int h)
 {
     SDL_Rect bounds;

-    // Check that video_display corresponds to a display that really exists,
-    // and if it doesn't, reset it.
-    if (video_display < 0 || video_display >= SDL_GetNumVideoDisplays())
-    {
-        fprintf(stderr,
-                "CenterWindow: We were configured to run on display #%d, but "
-                "it no longer exists (max %d). Moving to display 0.\n",
-                video_display, SDL_GetNumVideoDisplays() - 1);
-        video_display = 0;
-    }
-
     if (SDL_GetDisplayBounds(video_display, &bounds) < 0)
     {
         fprintf(stderr, "CenterWindow: Failed to read display bounds "
@@ -1106,6 +1095,17 @@ static void CenterWindow(int *x, int *y, int w, int h)

 void I_GetWindowPosition(int *x, int *y, int w, int h)
 {
+    // Check that video_display corresponds to a display that really exists,
+    // and if it doesn't, reset it.
+    if (video_display < 0 || video_display >= SDL_GetNumVideoDisplays())
+    {
+        fprintf(stderr,
+                "I_GetWindowPosition: We were configured to run on display #%d, "
+                "but it no longer exists (max %d). Moving to display 0.\n",
+                video_display, SDL_GetNumVideoDisplays() - 1);
+        video_display = 0;
+    }
+
     // in fullscreen mode, the window "position" still matters, because
     // we use it to control which display we run fullscreen on.