From b7fd154b918000db8f49b863781e042679c76fe0 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 26 Apr 2021 20:06:30 +0200 Subject: [PATCH] refactor: move dispose logic out of entrypoint --- Dalamud/Dalamud.cs | 10 ++++++++++ Dalamud/EntryPoint.cs | 5 ----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 64aa81c0e..5203107fd 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -31,6 +31,8 @@ namespace Dalamud private readonly string baseDirectory; + private bool hasDisposedPlugins = false; + #endregion /// @@ -351,8 +353,13 @@ namespace Dalamud this.finishUnloadSignal?.WaitOne(); } + /// + /// Dispose subsystems related to plugin handling. + /// public void DisposePlugins() { + this.hasDisposedPlugins = true; + // this must be done before unloading plugins, or it can cause a race condition // due to rendering happening on another thread, where a plugin might receive // a render call after it has been disposed, which can crash if it attempts to @@ -378,6 +385,9 @@ namespace Dalamud { try { + if (!this.hasDisposedPlugins) + this.DisposePlugins(); + this.Framework?.Dispose(); this.ClientState?.Dispose(); diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 3c9bddcbd..2895a13e0 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -59,11 +59,6 @@ namespace Dalamud // Run session dalamud.Start(); dalamud.WaitForUnload(); - if (dalamud.Framework.DispatchUpdateEvents) - { - dalamud.DisposePlugins(); - Thread.Sleep(100); - } dalamud.Dispose(); }