Skip to content

Commit 1a33f4d

Browse files
committed
Properly reset custom triggers (fix duplicates)
Previously triggers would not be cleared properly and so be duplicated. (Static variables seem to persist between entering/exiting playmode)
1 parent b478c7b commit 1a33f4d

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

scripts/DllManipulator.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ internal static void Initialize(int unityMainThreadId, string assetsPath)
100100
LoadAll();
101101
}
102102

103+
/// <summary>
104+
/// Will unload/forget all dll's and reset the state
105+
/// </summary>
106+
public static void Reset()
107+
{
108+
UnloadAll();
109+
ForgetAllDlls();
110+
ClearCrashLogs();
111+
112+
_customLoadedTriggers?.Clear();
113+
_customAfterUnloadTriggers?.Clear();
114+
_customBeforeUnloadTriggers?.Clear();
115+
}
116+
103117
private static void RegisterTriggerMethod(MethodInfo method, ref List<MethodInfo> triggersList)
104118
{
105119
var parameters = method.GetParameters();

scripts/DllManipulatorScript.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ private void OnDestroy()
9292
//On Preloaded mode this leads to NullReferenceException, but on Lazy mode the DLL and function would be just reloaded so we would up with loaded DLL after game exit.
9393
//Thankfully thread safety with Lazy mode is not implemented yet.
9494

95-
DllManipulator.UnloadAll();
96-
DllManipulator.ForgetAllDlls();
97-
DllManipulator.ClearCrashLogs();
95+
DllManipulator.Reset();
9896
_singletonInstance = null;
9997
}
10098
}

0 commit comments

Comments
 (0)