refactor: make all PluginInterface classes explicitly disposable

This commit is contained in:
goaaats 2022-01-08 03:00:56 +01:00
parent 33f230fa75
commit 2d90598b70
No known key found for this signature in database
GPG key ID: F18F057873895461
16 changed files with 43 additions and 29 deletions

View file

@ -93,7 +93,7 @@ namespace Dalamud.CorePlugin
this.windowSystem.RemoveAllWindows();
this.Interface.Dispose();
this.Interface.ExplicitDispose();
}
/// <summary>

View file

@ -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<Framework>.GetNullable()?.Dispose();
Service<ClientState>.GetNullable()?.Dispose();
Service<Framework>.GetNullable()?.ExplicitDispose();
Service<ClientState>.GetNullable()?.ExplicitDispose();
this.unloadSignal?.Dispose();
Service<WinSockHandlers>.GetNullable()?.Dispose();
Service<DataManager>.GetNullable()?.Dispose();
Service<DataManager>.GetNullable()?.ExplicitDispose();
Service<AntiDebug>.GetNullable()?.Dispose();
Service<DalamudAtkTweaks>.GetNullable()?.Dispose();
Service<HookManager>.GetNullable()?.Dispose();

View file

@ -271,7 +271,7 @@ namespace Dalamud.Data
/// <summary>
/// Dispose this DataManager.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.luminaCancellationTokenSource.Cancel();
}

View file

@ -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
/// <summary>
/// Dispose of managed and unmanaged resources.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.setupTerritoryTypeHook.Dispose();
Service<Condition>.Get().Dispose();
Service<GamepadState>.Get().Dispose();
Service<Condition>.Get().ExplicitDispose();
Service<GamepadState>.Get().ExplicitDispose();
Service<Framework>.Get().Update -= this.FrameworkOnOnUpdateEvent;
Service<NetworkHandlers>.Get().CfPop -= this.NetworkHandlersOnCfPop;
}

View file

@ -136,7 +136,7 @@ namespace Dalamud.Game.ClientState.Conditions
/// <summary>
/// Disposes this instance, alongside its hooks.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
GC.SuppressFinalize(this);
this.Dispose(true);

View file

@ -175,7 +175,7 @@ namespace Dalamud.Game.ClientState.GamePad
/// <summary>
/// Disposes this instance, alongside its hooks.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);

View file

@ -135,10 +135,10 @@ namespace Dalamud.Game
/// <summary>
/// Dispose of managed and unmanaged resources.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
Service<GameGui>.GetNullable()?.Dispose();
Service<GameNetwork>.GetNullable()?.Dispose();
Service<GameGui>.GetNullable()?.ExplicitDispose();
Service<GameNetwork>.GetNullable()?.ExplicitDispose();
this.updateHook?.Disable();
this.destroyHook?.Disable();

View file

@ -139,7 +139,7 @@ namespace Dalamud.Game.Gui
/// <summary>
/// Dispose of managed and unmanaged resources.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.printMessageHook.Dispose();
this.populateItemLinkHook.Dispose();

View file

@ -444,12 +444,12 @@ namespace Dalamud.Game.Gui
/// <summary>
/// Disables the hooks and submodules of this module.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
Service<ChatGui>.Get().Dispose();
Service<ToastGui>.Get().Dispose();
Service<FlyTextGui>.Get().Dispose();
Service<PartyFinderGui>.Get().Dispose();
Service<ChatGui>.Get().ExplicitDispose();
Service<ToastGui>.Get().ExplicitDispose();
Service<FlyTextGui>.Get().ExplicitDispose();
Service<PartyFinderGui>.Get().ExplicitDispose();
this.setGlobalBgmHook.Dispose();
this.handleItemHoverHook.Dispose();
this.handleItemOutHook.Dispose();

View file

@ -61,9 +61,9 @@ namespace Dalamud.Game.Gui.PartyFinder
}
/// <summary>
/// Dispose of m anaged and unmanaged resources.
/// Dispose of managed and unmanaged resources.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.receiveListingHook.Dispose();

View file

@ -110,7 +110,7 @@ namespace Dalamud.Game.Gui.Toast
/// <summary>
/// Disposes of managed and unmanaged resources.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.showNormalToastHook.Dispose();
this.showQuestToastHook.Dispose();

View file

@ -72,7 +72,7 @@ namespace Dalamud.Game.Network
/// <summary>
/// Dispose of managed and unmanaged resources.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.processZonePacketDownHook.Dispose();
this.processZonePacketUpHook.Dispose();

View file

@ -226,7 +226,7 @@ namespace Dalamud.Interface
/// <summary>
/// Unregister the UiBuilder. Do not call this in plugin code.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
var interfaceManager = Service<InterfaceManager>.Get();

View file

@ -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
/// <summary>
/// Unregister your plugin and dispose all references.
/// </summary>
public void Dispose()
void IDisposable.Dispose()
{
this.UiBuilder.Dispose();
this.UiBuilder.ExplicitDispose();
Service<ChatGui>.Get().RemoveChatLinkHandler(this.pluginName);
Service<Localization>.Get().LocalizationChanged -= this.OnLocalizationChanged;
Service<DalamudConfiguration>.Get().DalamudConfigurationSaved -= this.OnDalamudConfigurationSaved;

View file

@ -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;

View file

@ -457,6 +457,16 @@ namespace Dalamud.Utility
Process.Start(process);
}
/// <summary>
/// Dispose this object.
/// </summary>
/// <param name="obj">The object to dispose.</param>
/// <typeparam name="T">The type of object to dispose.</typeparam>
internal static void ExplicitDispose<T>(this T obj) where T : IDisposable
{
obj.Dispose();
}
private static unsafe void ShowValue(ulong addr, IEnumerable<string> path, Type type, object value)
{
if (type.IsPointer)