From d9e24c10f98b81c4d80880b9b173efe7dc604ec7 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 16 Jan 2023 02:26:19 -0800 Subject: [PATCH 1/2] Null check on player object. I'm getting this exception a lot in my game, and it's player. [Error : Unity Log] NullReferenceException: Object reference not set to an instance of an object Stack trace: ValheimPlus.UI.HotkeyBar_UpdateIcons_Patch.DisplayAmmoCountsUnderBowHotbarIcon (HotkeyBar __instance, Player player) (at C:/Users/twili/RiderProjects/ValheimPlus/ValheimPlus/UI/HotkeyBar.cs:40) ValheimPlus.UI.HotkeyBar_UpdateIcons_Patch.Postfix (HotkeyBar& __instance, Player& player) (at C:/Users/twili/RiderProjects/ValheimPlus/ValheimPlus/UI/HotkeyBar.cs:21) (wrapper dynamic-method) HotkeyBar.DMD(HotkeyBar,Player) HotkeyBar.Update () (at <35c0f7aa1999477788815a7bf78200d7>:0) --- ValheimPlus/UI/HotkeyBar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ValheimPlus/UI/HotkeyBar.cs b/ValheimPlus/UI/HotkeyBar.cs index 9a8c3de0..8be3b6dc 100644 --- a/ValheimPlus/UI/HotkeyBar.cs +++ b/ValheimPlus/UI/HotkeyBar.cs @@ -37,7 +37,7 @@ private static void DisplayAmmoCountsUnderBowHotbarIcon(HotkeyBar __instance, Pl } // If there is no bow or it is not equipped, remove the text element - if (bow == null || (Configuration.Current.Hud.displayBowAmmoCounts == 1 && !player.IsItemEquiped(bow))) + if (bow == null || (Configuration.Current.Hud.displayBowAmmoCounts == 1 && player != null && !player.IsItemEquiped(bow))) { if (ammoCounter != null) { From a8267694ea1b7c95c3e6b06293fffad8b6fe969e Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 16 Jan 2023 02:35:06 -0800 Subject: [PATCH 2/2] Update Minimap custom pin removal to not throw error. Can't modify a collection while you iterate through it without getting an exception. Usually works fine for the player, but it does throw an exception and is bad practice. Could feasibly cause the player an issue if two items were somehow destroyed at once. Stacktrace: [Error : Unity Log] InvalidOperationException: Collection was modified; enumeration operation may not execute. Stack trace: System.Collections.Generic.Dictionary`2+Enumerator[TKey,TValue].MoveNext () (at <695d1cc93cca45069c528c15c9fdd749>:0) ValheimPlus.GameClasses.displayCartsAndBoatsOnMap+Minimap_UpdateMap_Patch.Postfix (Minimap& __instance, Player player, System.Single dt, System.Boolean takeInput) (at C:/Users/twili/RiderProjects/ValheimPlus/ValheimPlus/GameClasses/Minimap.cs:419) (wrapper dynamic-method) Minimap.DMD(Minimap,Player,single,bool) Minimap.Update () (at <35c0f7aa1999477788815a7bf78200d7>:0) --- ValheimPlus/GameClasses/Minimap.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ValheimPlus/GameClasses/Minimap.cs b/ValheimPlus/GameClasses/Minimap.cs index 1693c193..9cfb51a3 100644 --- a/ValheimPlus/GameClasses/Minimap.cs +++ b/ValheimPlus/GameClasses/Minimap.cs @@ -414,6 +414,8 @@ public static void Postfix(ref Minimap __instance, Player player, float dt, bool } } } + + List toRemove = new List(); // clear pins for destroyed objects foreach (KeyValuePair pin in customPins) @@ -421,9 +423,13 @@ public static void Postfix(ref Minimap __instance, Player player, float dt, bool if (!pin.Key.IsValid()) { __instance.RemovePin(pin.Value); - customPins.Remove(pin.Key); + toRemove.Add(pin.Key); } } + + foreach (ZDO zdo in toRemove) { + customPins.Remove(zdo); + } } } }