Skip to content

Commit

Permalink
fix: upper bounds check correction for resolution, avoid crashing if …
Browse files Browse the repository at this point in the history
…resolution out of bounds on settings menu (#2026)
  • Loading branch information
lodicolo authored Nov 3, 2023
1 parent c3cdd3f commit 48e3d64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Intersect.Client/Interface/Shared/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ public void Show(bool returnToMenu = false)
}
else
{
resolutionLabel = Graphics.Renderer.GetValidVideoModes()[Globals.Database.TargetResolution];
var validVideoModes = Graphics.Renderer.GetValidVideoModes();
var targetResolution = Globals.Database.TargetResolution;
resolutionLabel = targetResolution < 0 || validVideoModes.Count <= targetResolution ? Strings.Settings.ResolutionCustom : validVideoModes[Globals.Database.TargetResolution];
}

mResolutionList.SelectByText(resolutionLabel);
Expand Down
6 changes: 3 additions & 3 deletions Intersect.Client/MonoGame/Graphics/MonoRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,16 +826,16 @@ public override void Init()
}
}

var targetResolution = MathHelper.Clamp(database.TargetResolution, 0, validVideoModes.Count);
var targetResolution = MathHelper.Clamp(database.TargetResolution, 0, validVideoModes.Count - 1);

if (targetResolution != database.TargetResolution)
{
Debug.Assert(database != default, "database != null");
database.TargetResolution = 0;
database.TargetResolution = targetResolution;
database.SavePreference("Resolution", database.TargetResolution.ToString(CultureInfo.InvariantCulture));
}

var targetVideoMode = validVideoModes?[MathHelper.Clamp(targetResolution, 0, validVideoModes.Count - 1)];
var targetVideoMode = validVideoModes[targetResolution];
if (!string.IsNullOrWhiteSpace(targetVideoMode) && Resolution.TryParse(targetVideoMode, out var resolution))
{
PreferredResolution = resolution;
Expand Down

0 comments on commit 48e3d64

Please sign in to comment.