From 4dfbee7192000c0047a73d48fb10a33d39261d89 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 10 Dec 2017 21:05:13 +0000 Subject: [PATCH] In case the resolution settings in the config file have wrong values, the main window is not appearing, forcing here minimum decent values. --- Source/Globals.cpp | 2 ++ Source/User/Settings.cpp | 20 ++++++++++---------- Source/User/Settings.hpp | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 3a4d544..41d81cb 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -46,6 +46,8 @@ int difficulty = 0; float multiplier = 0; float realmultiplier = 0; float screenwidth = 0, screenheight = 0; +float minscreenwidth = 640, minscreenheight = 480; +float maxscreenwidth = 3000, maxscreenheight = 3000; bool fullscreen = 0; float viewdistance = 0; XYZ viewer; diff --git a/Source/User/Settings.cpp b/Source/User/Settings.cpp index fedc77e..4890f45 100644 --- a/Source/User/Settings.cpp +++ b/Source/User/Settings.cpp @@ -76,16 +76,10 @@ void SaveSettings() if (newdetail > 2) { newdetail = 2; } - if (newscreenwidth > 3000) { + if (newscreenwidth < minscreenwidth || newscreenwidth > maxscreenwidth) { newscreenwidth = screenwidth; } - if (newscreenwidth < 0) { - newscreenwidth = screenwidth; - } - if (newscreenheight > 3000) { - newscreenheight = screenheight; - } - if (newscreenheight < 0) { + if (newscreenheight < minscreenheight || newscreenheight > maxscreenheight) { newscreenheight = screenheight; } errno = 0; @@ -207,8 +201,14 @@ bool LoadSettings() if (!strncmp(setting, "Screenwidth", 11)) { ipstream >> kContextWidth; + if (kContextWidth < (int)minscreenwidth || kContextWidth > (int)maxscreenwidth) { + kContextWidth = (int)minscreenwidth; + } } else if (!strncmp(setting, "Screenheight", 12)) { ipstream >> kContextHeight; + if (kContextHeight < (int)minscreenheight || kContextHeight > (int)maxscreenheight) { + kContextHeight = (int)minscreenheight; + } } else if (!strncmp(setting, "Fullscreen", 10)) { ipstream >> fullscreen; } else if (!strncmp(setting, "Mouse sensitivity", 17)) { @@ -316,10 +316,10 @@ bool LoadSettings() if (detail < 0) { detail = 0; } - if (screenwidth < 0) { + if (screenwidth < minscreenwidth || screenwidth > maxscreenwidth) { screenwidth = 1024; } - if (screenheight < 0) { + if (screenheight < minscreenheight || screenheight > maxscreenheight) { screenheight = 768; } diff --git a/Source/User/Settings.hpp b/Source/User/Settings.hpp index e07d895..254250a 100644 --- a/Source/User/Settings.hpp +++ b/Source/User/Settings.hpp @@ -51,6 +51,8 @@ extern int kContextWidth; extern int kContextHeight; extern float screenwidth, screenheight; extern bool fullscreen; +extern float minscreenwidth, minscreenheight; +extern float maxscreenwidth, maxscreenheight; void DefaultSettings(); void SaveSettings(); -- 2.39.5