diff --git a/Dalamud.CorePlugin/PluginImpl.cs b/Dalamud.CorePlugin/PluginImpl.cs index de7e66270..5ed6d02ac 100644 --- a/Dalamud.CorePlugin/PluginImpl.cs +++ b/Dalamud.CorePlugin/PluginImpl.cs @@ -93,7 +93,7 @@ namespace Dalamud.CorePlugin this.windowSystem.RemoveAllWindows(); - this.Interface.Dispose(); + this.Interface.ExplicitDispose(); } /// diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 6a3e7df33..6bbaa08bc 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -23,6 +23,7 @@ using Dalamud.Logging.Internal; using Dalamud.Plugin.Internal; using Dalamud.Plugin.Ipc.Internal; using Dalamud.Support; +using Dalamud.Utility; using Serilog; using Serilog.Core; using Serilog.Events; @@ -334,13 +335,13 @@ namespace Dalamud Thread.Sleep(100); } - Service.GetNullable()?.Dispose(); - Service.GetNullable()?.Dispose(); + Service.GetNullable()?.ExplicitDispose(); + Service.GetNullable()?.ExplicitDispose(); this.unloadSignal?.Dispose(); Service.GetNullable()?.Dispose(); - Service.GetNullable()?.Dispose(); + Service.GetNullable()?.ExplicitDispose(); Service.GetNullable()?.Dispose(); Service.GetNullable()?.Dispose(); Service.GetNullable()?.Dispose(); diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index a78f0eec3..8697dc930 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -271,7 +271,7 @@ namespace Dalamud.Data /// /// Dispose this DataManager. /// - public void Dispose() + void IDisposable.Dispose() { this.luminaCancellationTokenSource.Cancel(); } diff --git a/Dalamud/Game/ClientState/ClientState.cs b/Dalamud/Game/ClientState/ClientState.cs index 0e8a3a58c..88b8e885c 100644 --- a/Dalamud/Game/ClientState/ClientState.cs +++ b/Dalamud/Game/ClientState/ClientState.cs @@ -15,6 +15,7 @@ using Dalamud.Game.Network.Internal; using Dalamud.Hooking; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Utility; using Serilog; namespace Dalamud.Game.ClientState @@ -136,11 +137,11 @@ namespace Dalamud.Game.ClientState /// /// Dispose of managed and unmanaged resources. /// - public void Dispose() + void IDisposable.Dispose() { this.setupTerritoryTypeHook.Dispose(); - Service.Get().Dispose(); - Service.Get().Dispose(); + Service.Get().ExplicitDispose(); + Service.Get().ExplicitDispose(); Service.Get().Update -= this.FrameworkOnOnUpdateEvent; Service.Get().CfPop -= this.NetworkHandlersOnCfPop; } diff --git a/Dalamud/Game/ClientState/Conditions/Condition.cs b/Dalamud/Game/ClientState/Conditions/Condition.cs index 597f4725b..7c78bb17c 100644 --- a/Dalamud/Game/ClientState/Conditions/Condition.cs +++ b/Dalamud/Game/ClientState/Conditions/Condition.cs @@ -136,7 +136,7 @@ namespace Dalamud.Game.ClientState.Conditions /// /// Disposes this instance, alongside its hooks. /// - public void Dispose() + void IDisposable.Dispose() { GC.SuppressFinalize(this); this.Dispose(true); diff --git a/Dalamud/Game/ClientState/GamePad/GamepadState.cs b/Dalamud/Game/ClientState/GamePad/GamepadState.cs index 8759673b2..4a703ff29 100644 --- a/Dalamud/Game/ClientState/GamePad/GamepadState.cs +++ b/Dalamud/Game/ClientState/GamePad/GamepadState.cs @@ -175,7 +175,7 @@ namespace Dalamud.Game.ClientState.GamePad /// /// Disposes this instance, alongside its hooks. /// - public void Dispose() + void IDisposable.Dispose() { this.Dispose(true); GC.SuppressFinalize(this); diff --git a/Dalamud/Game/Framework.cs b/Dalamud/Game/Framework.cs index 38a978e1f..ede9f7cbb 100644 --- a/Dalamud/Game/Framework.cs +++ b/Dalamud/Game/Framework.cs @@ -135,10 +135,10 @@ namespace Dalamud.Game /// /// Dispose of managed and unmanaged resources. /// - public void Dispose() + void IDisposable.Dispose() { - Service.GetNullable()?.Dispose(); - Service.GetNullable()?.Dispose(); + Service.GetNullable()?.ExplicitDispose(); + Service.GetNullable()?.ExplicitDispose(); this.updateHook?.Disable(); this.destroyHook?.Disable(); diff --git a/Dalamud/Game/Gui/ChatGui.cs b/Dalamud/Game/Gui/ChatGui.cs index 0aa7bb94f..d1563d825 100644 --- a/Dalamud/Game/Gui/ChatGui.cs +++ b/Dalamud/Game/Gui/ChatGui.cs @@ -139,7 +139,7 @@ namespace Dalamud.Game.Gui /// /// Dispose of managed and unmanaged resources. /// - public void Dispose() + void IDisposable.Dispose() { this.printMessageHook.Dispose(); this.populateItemLinkHook.Dispose(); diff --git a/Dalamud/Game/Gui/GameGui.cs b/Dalamud/Game/Gui/GameGui.cs index 0c1ae4e51..d3282df07 100644 --- a/Dalamud/Game/Gui/GameGui.cs +++ b/Dalamud/Game/Gui/GameGui.cs @@ -444,12 +444,12 @@ namespace Dalamud.Game.Gui /// /// Disables the hooks and submodules of this module. /// - public void Dispose() + void IDisposable.Dispose() { - Service.Get().Dispose(); - Service.Get().Dispose(); - Service.Get().Dispose(); - Service.Get().Dispose(); + Service.Get().ExplicitDispose(); + Service.Get().ExplicitDispose(); + Service.Get().ExplicitDispose(); + Service.Get().ExplicitDispose(); this.setGlobalBgmHook.Dispose(); this.handleItemHoverHook.Dispose(); this.handleItemOutHook.Dispose(); diff --git a/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs b/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs index 6d2a7818d..140256b4c 100644 --- a/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs +++ b/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs @@ -61,9 +61,9 @@ namespace Dalamud.Game.Gui.PartyFinder } /// - /// Dispose of m anaged and unmanaged resources. + /// Dispose of managed and unmanaged resources. /// - public void Dispose() + void IDisposable.Dispose() { this.receiveListingHook.Dispose(); diff --git a/Dalamud/Game/Gui/Toast/ToastGui.cs b/Dalamud/Game/Gui/Toast/ToastGui.cs index ca24df197..1f773def8 100644 --- a/Dalamud/Game/Gui/Toast/ToastGui.cs +++ b/Dalamud/Game/Gui/Toast/ToastGui.cs @@ -110,7 +110,7 @@ namespace Dalamud.Game.Gui.Toast /// /// Disposes of managed and unmanaged resources. /// - public void Dispose() + void IDisposable.Dispose() { this.showNormalToastHook.Dispose(); this.showQuestToastHook.Dispose(); diff --git a/Dalamud/Game/Network/GameNetwork.cs b/Dalamud/Game/Network/GameNetwork.cs index e4feac4d0..039fce90c 100644 --- a/Dalamud/Game/Network/GameNetwork.cs +++ b/Dalamud/Game/Network/GameNetwork.cs @@ -72,7 +72,7 @@ namespace Dalamud.Game.Network /// /// Dispose of managed and unmanaged resources. /// - public void Dispose() + void IDisposable.Dispose() { this.processZonePacketDownHook.Dispose(); this.processZonePacketUpHook.Dispose(); diff --git a/Dalamud/Interface/UiBuilder.cs b/Dalamud/Interface/UiBuilder.cs index 7811ccd00..445ac3618 100644 --- a/Dalamud/Interface/UiBuilder.cs +++ b/Dalamud/Interface/UiBuilder.cs @@ -226,7 +226,7 @@ namespace Dalamud.Interface /// /// Unregister the UiBuilder. Do not call this in plugin code. /// - public void Dispose() + void IDisposable.Dispose() { var interfaceManager = Service.Get(); diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index d41a7053b..974731875 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -19,6 +19,7 @@ using Dalamud.Plugin.Internal; using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc.Exceptions; using Dalamud.Plugin.Ipc.Internal; +using Dalamud.Utility; namespace Dalamud.Plugin { @@ -383,9 +384,9 @@ namespace Dalamud.Plugin /// /// Unregister your plugin and dispose all references. /// - public void Dispose() + void IDisposable.Dispose() { - this.UiBuilder.Dispose(); + this.UiBuilder.ExplicitDispose(); Service.Get().RemoveChatLinkHandler(this.pluginName); Service.Get().LocalizationChanged -= this.OnLocalizationChanged; Service.Get().DalamudConfigurationSaved -= this.OnDalamudConfigurationSaved; diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index a1da03316..971e91b2b 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -10,6 +10,7 @@ using Dalamud.Logging.Internal; using Dalamud.Plugin.Internal.Exceptions; using Dalamud.Plugin.Internal.Loader; using Dalamud.Plugin.Internal.Types; +using Dalamud.Utility; namespace Dalamud.Plugin.Internal { @@ -209,7 +210,7 @@ namespace Dalamud.Plugin.Internal this.instance?.Dispose(); this.instance = null; - this.DalamudInterface?.Dispose(); + this.DalamudInterface?.ExplicitDispose(); this.DalamudInterface = null; this.pluginType = null; @@ -332,7 +333,7 @@ namespace Dalamud.Plugin.Internal if (this.instance == null) { this.State = PluginState.LoadError; - this.DalamudInterface.Dispose(); + this.DalamudInterface.ExplicitDispose(); Log.Error($"Error while loading {this.Name}, failed to bind and call the plugin constructor"); return; } @@ -382,7 +383,7 @@ namespace Dalamud.Plugin.Internal this.instance?.Dispose(); this.instance = null; - this.DalamudInterface?.Dispose(); + this.DalamudInterface?.ExplicitDispose(); this.DalamudInterface = null; this.pluginType = null; diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs index 88f798540..6f914b918 100644 --- a/Dalamud/Utility/Util.cs +++ b/Dalamud/Utility/Util.cs @@ -457,6 +457,16 @@ namespace Dalamud.Utility Process.Start(process); } + /// + /// Dispose this object. + /// + /// The object to dispose. + /// The type of object to dispose. + internal static void ExplicitDispose(this T obj) where T : IDisposable + { + obj.Dispose(); + } + private static unsafe void ShowValue(ulong addr, IEnumerable path, Type type, object value) { if (type.IsPointer)