Skip to content

Commit

Permalink
Fix event handler leak in keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Feb 1, 2024
1 parent 2ae7e3e commit 19b3917
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:**
Expand Down
5 changes: 2 additions & 3 deletions LCVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>LCVR</AssemblyName>
<Description>Collecting Scrap in VR</Description>
<Version>1.1.7</Version>
<Version>1.1.8</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>12.0</LangVersion>
<Title>LethalCompanyVR</Title>
Expand All @@ -31,8 +31,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2"
PrivateAssets="all" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion LCVR/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Patches/UIPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private static void InjectDebugScreen()
var description = modDebugPanel.Find("Panel/DemoText").GetComponent<TextMeshProUGUI>();

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<Image>();
picture.transform.SetSiblingIndex(0);
Expand Down
16 changes: 13 additions & 3 deletions UI/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TMP_InputField> inputFields = [];
private readonly Dictionary<TMP_InputField, UnityAction<string>> inputFields = [];

public NonNativeKeyboard keyboard;

Expand All @@ -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<string>((_) =>
{
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);
}
}
}

0 comments on commit 19b3917

Please sign in to comment.