From 66b9ff570434d3763b05c0fc39c5c714e1af05d9 Mon Sep 17 00:00:00 2001 From: Nick Blakely Date: Sun, 16 Aug 2020 01:32:49 -0700 Subject: [PATCH] Fix rare crash when populating AA/aniso options. --- Giants.Launcher/OptionsForm.cs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Giants.Launcher/OptionsForm.cs b/Giants.Launcher/OptionsForm.cs index 6f7d8d2..9825a22 100644 --- a/Giants.Launcher/OptionsForm.cs +++ b/Giants.Launcher/OptionsForm.cs @@ -20,14 +20,20 @@ namespace Giants.Launcher private void OptionsForm_Load(object sender, EventArgs e) { - this.PopulateResolution(); + // Must come first as other options depend on it + this.PopulateRenderers(); + + this.PopulateResolution(); + this.PopulateAnisotropy(); + this.PopulateAntialiasing(); + this.SetOptions(); } - private void SetOptions() - { - this.cmbRenderer.Items.Clear(); - this.cmbRenderer.Items.AddRange( + private void PopulateRenderers() + { + this.cmbRenderer.Items.Clear(); + this.cmbRenderer.Items.AddRange( GameSettings.CompatibleRenderers .Disambiguate() .ToList() @@ -38,26 +44,29 @@ namespace Giants.Launcher if (renderer != null) { - this.cmbRenderer.SelectedItem = renderer; + this.cmbRenderer.SelectedItem = renderer; } else { renderer = GameSettings.CompatibleRenderers.Find(r => r.Name == "DirectX 7"); - this.cmbRenderer.SelectedItem = renderer; + this.cmbRenderer.SelectedItem = renderer; } + } + private void SetOptions() + { var resolutions = (List)this.cmbResolution.DataSource; this.cmbResolution.SelectedItem = resolutions.Find(r => r.Width == GameSettings.Get(SettingKeys.VideoWidth) && r.Height == GameSettings.Get(SettingKeys.VideoHeight)); if (this.cmbResolution.SelectedItem == null) this.cmbResolution.SelectedIndex = 0; - var AntialiasingOptions = (List>)this.cmbAntialiasing.DataSource; - this.cmbAntialiasing.SelectedItem = AntialiasingOptions.Find(o => o.Value == GameSettings.Get(SettingKeys.Antialiasing)); + var antialiasingOptions = (List>)this.cmbAntialiasing.DataSource; + this.cmbAntialiasing.SelectedItem = antialiasingOptions.Find(o => o.Value == GameSettings.Get(SettingKeys.Antialiasing)); if (this.cmbAntialiasing.SelectedItem == null) this.cmbAntialiasing.SelectedIndex = 0; - var AnisotropyOptions = (List>)this.cmbAnisotropy.DataSource; - this.cmbAnisotropy.SelectedItem = AnisotropyOptions.Find(o => o.Value == GameSettings.Get(SettingKeys.AnisotropicFiltering)); + var anisotropyOptions = (List>)this.cmbAnisotropy.DataSource; + this.cmbAnisotropy.SelectedItem = anisotropyOptions.Find(o => o.Value == GameSettings.Get(SettingKeys.AnisotropicFiltering)); if (this.cmbAnisotropy.SelectedItem == null) this.cmbAnisotropy.SelectedIndex = 0; @@ -169,9 +178,6 @@ namespace Giants.Launcher private void cmbRenderer_SelectedIndexChanged(object sender, EventArgs e) { - this.PopulateAntialiasing(); - this.PopulateAnisotropy(); - bool windowed = GameSettings.Get(SettingKeys.Windowed) == 1; if (windowed) {