Skip to content

Commit

Permalink
Fix Mod Options again. (#485)
Browse files Browse the repository at this point in the history
Fix: Add try catch to AddOptionsToPanel to catch when a mod breaks the BuildModOptions in their override.
Fix: Don't modify lists that you're enumerating through in the BuildModOptions for ConfigFile options menu's
  • Loading branch information
MrPurple6411 committed Oct 9, 2023
1 parent c64b52b commit de757bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Nautilus/Options/Attributes/OptionsMenuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public override void BuildModOptions(uGUI_TabbedControlsPanel panel, int modsTab
if (ConfigFileMetadata.MenuAttribute.LoadOn.HasFlag(MenuAttribute.LoadEvents.MenuOpened))
{
ConfigFileMetadata.Config.Load();
foreach(var option in options)
foreach(var option in new List<OptionItem>(Options))
{
RemoveItem(option.Id);
}
Expand Down
15 changes: 8 additions & 7 deletions Nautilus/Options/ModOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ public bool RemoveItem(string id)

internal void AddOptionsToPanel(uGUI_TabbedControlsPanel panel, int modsTabIndex)
{
/*
* Since Subnautica runs on a very old CLR, iterating on a list that is changed in the loop throws an exception.
* To prevent the mistake of calling RemoveItem or AddItem while iterating on the Options property, we pass a copy of
* The Options property.
*/
var options = Options.ToList();
BuildModOptions(panel, modsTabIndex, options);
try
{
BuildModOptions(panel, modsTabIndex, Options);
}
catch(Exception ex)
{
InternalLogger.Error($"{Name} Failed to BuildModOptions with exception: \n {ex}");
}
}

/// <summary>
Expand Down

0 comments on commit de757bf

Please sign in to comment.