From 19b3917aa3a71bbd4364cc2c7c6c9462c1293e19 Mon Sep 17 00:00:00 2001 From: DaXcess Date: Thu, 1 Feb 2024 18:21:25 +0100 Subject: [PATCH] Fix event handler leak in keyboard --- CHANGELOG.md | 6 ++++++ LCVR.csproj | 5 ++--- LCVR/Plugin.cs | 2 +- Patches/UIPatches.cs | 2 +- UI/Keyboard.cs | 16 +++++++++++++--- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c03c4352..df0a0680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.1.8 + +**Bug fixes:** + +- Fixed event handler leak in the Keyboard causing the game to hang + # 1.1.7 **Adjustments:** diff --git a/LCVR.csproj b/LCVR.csproj index e3c55951..56397dd5 100644 --- a/LCVR.csproj +++ b/LCVR.csproj @@ -4,7 +4,7 @@ netstandard2.1 LCVR Collecting Scrap in VR - 1.1.7 + 1.1.8 true 12.0 LethalCompanyVR @@ -31,8 +31,7 @@ - + diff --git a/LCVR/Plugin.cs b/LCVR/Plugin.cs index 2a8e6cd3..2b13651d 100644 --- a/LCVR/Plugin.cs +++ b/LCVR/Plugin.cs @@ -35,7 +35,7 @@ public class Plugin : BaseUnityPlugin { public const string PLUGIN_GUID = "io.daxcess.lcvr"; public const string PLUGIN_NAME = "LCVR"; - public const string PLUGIN_VERSION = "1.1.7"; + public const string PLUGIN_VERSION = "1.1.8"; private readonly string[] GAME_ASSEMBLY_HASHES = [ "AAC6149C355A19865C0F67FD0C1D7111D4F418EF94D700265B591665B4CDCE73", // V45 diff --git a/Patches/UIPatches.cs b/Patches/UIPatches.cs index d57f1999..db130b9f 100644 --- a/Patches/UIPatches.cs +++ b/Patches/UIPatches.cs @@ -326,7 +326,7 @@ private static void InjectDebugScreen() var description = modDebugPanel.Find("Panel/DemoText").GetComponent(); title.text = "LCVR DEBUG BUILD!"; - description.text = "You are using a development version of LCVR! Expect this version of the mod to be highly unstable!"; + description.text = "You are using a development version of LCVR! This means that some features might not work as advertised, or gameplay being affected in unexpected ways. Do not use this version if you wish to keep your save files intact!"; var picture = modDebugPanel.Find("Panel/Picture").GetComponent(); picture.transform.SetSiblingIndex(0); diff --git a/UI/Keyboard.cs b/UI/Keyboard.cs index 06f4e77a..060aaf58 100644 --- a/UI/Keyboard.cs +++ b/UI/Keyboard.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; using TMPro; using UnityEngine; +using UnityEngine.Events; namespace LCVR.UI { internal class Keyboard : MonoBehaviour { - private readonly List inputFields = []; + private readonly Dictionary> inputFields = []; public NonNativeKeyboard keyboard; @@ -33,15 +34,24 @@ private void PopulateInputs() foreach (var input in inputs) { - if (inputFields.Contains(input)) + if (inputFields.ContainsKey(input)) continue; - input.onSelect.AddListener((_) => + var action = new UnityAction((_) => { keyboard.InputField = input; keyboard.PresentKeyboard(); }); + + inputFields.Add(input, action); + input.onSelect.AddListener(action); } } + + private void OnDestroy() + { + foreach (var kv in inputFields) + kv.Key.onSelect.RemoveListener(kv.Value); + } } }