shithub: choc

Download patch

ref: 16a0f227362f330bd9be0598f136eed05c811969
parent: 5412004bfa32864c1034e81ee7b093d8887850f5
author: Simon Howard <fraggle@gmail.com>
date: Thu Mar 27 17:59:00 EDT 2014

video: Fix crash when running fullscreen with -2.

Remove special logic for setting a scale factor (2x, 3x, etc.) when
running fullscreen instead of windowed. This fixes a crash due to the
fact that I_GraphicsCheckCommandLine() is called before SDL's video
subsystem is initialized.

This makes -2 identical to -geometry 640x480, which is arguably a
better (more easily comprehensible) behavior.

Thanks to Fabian Greffrath for reporting the bug. This fixes #338.

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1546,83 +1546,23 @@
 
 static void SetScaleFactor(int factor)
 {
-    if (fullscreen)
-    {
-        // In fullscreen, find a mode that will provide this scale factor
+    int w, h;
 
-        SDL_Rect **modes;
-        SDL_Rect *best_mode;
-        screen_mode_t *scrmode;
-        int best_num_pixels, num_pixels;
-        int i;
+    // Pick 320x200 or 320x240, depending on aspect ratio correct
 
-        modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
-
-        best_mode = NULL;
-        best_num_pixels = INT_MAX;
-
-        for (i=0; modes[i] != NULL; ++i)
-        {
-            // What screen_mode_t will this use?
-
-            scrmode = I_FindScreenMode(modes[i]->w, modes[i]->h);
-
-            if (scrmode == NULL)
-            {
-                continue;
-            }
-
-            // Only choose modes that fit the requested scale factor.
-            //
-            // Note that this allows 320x240 as valid for 1x scale, as 
-            // 240/200 is rounded down to 1 by integer division.
-
-            if ((scrmode->width / SCREENWIDTH) != factor
-             || (scrmode->height / SCREENHEIGHT) != factor)
-            {
-                continue;
-            }
-
-            // Is this a better mode than what we currently have?
-
-            num_pixels = modes[i]->w * modes[i]->h;
-
-            if (num_pixels < best_num_pixels)
-            {
-                best_num_pixels = num_pixels;
-                best_mode = modes[i];
-            }
-        }
-
-        if (best_mode == NULL)
-        {
-            I_Error("No fullscreen graphics mode available to support "
-                    "%ix scale factor!", factor);
-        }
-
-        screen_width = best_mode->w;
-        screen_height = best_mode->h;
+    if (aspect_ratio_correct)
+    {
+        w = SCREENWIDTH;
+        h = SCREENHEIGHT_4_3;
     }
     else
     {
-        int w, h;
-
-        // Pick 320x200 or 320x240, depending on aspect ratio correct
-
-        if (aspect_ratio_correct)
-        {
-            w = SCREENWIDTH;
-            h = SCREENHEIGHT_4_3;
-        }
-        else 
-        {
-            w = SCREENWIDTH;
-            h = SCREENHEIGHT;
-        }
-
-        screen_width = w * factor;
-        screen_height = h * factor;
+        w = SCREENWIDTH;
+        h = SCREENHEIGHT;
     }
+
+    screen_width = w * factor;
+    screen_height = h * factor;
 }
 
 void I_GraphicsCheckCommandLine(void)