Skip to content

Commit 8819394

Browse files
committed
Prevent premature unload when DllManipulatorScript is duplicated
1 parent 600e754 commit 8819394

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

scripts/DllManipulatorScript.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,16 @@ private void OnEnable()
8686

8787
private void OnDestroy()
8888
{
89-
//Note on threading: Because we don't wait for other threads to finish, we might be stealing function delegates from under their nose if Unity doesn't happen to close them yet.
90-
//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.
91-
//Thankfully thread safety with Lazy mode is not implemented yet.
89+
if (_singletonInstance == this)
90+
{
91+
//Note on threading: Because we don't wait for other threads to finish, we might be stealing function delegates from under their nose if Unity doesn't happen to close them yet.
92+
//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.
93+
//Thankfully thread safety with Lazy mode is not implemented yet.
9294

93-
DllManipulator.UnloadAll();
94-
DllManipulator.ForgetAllDlls();
95-
DllManipulator.ClearCrashLogs();
95+
DllManipulator.UnloadAll();
96+
DllManipulator.ForgetAllDlls();
97+
DllManipulator.ClearCrashLogs();
98+
}
9699
}
97100
}
98101
}

0 commit comments

Comments
 (0)