mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 14:23:40 +01:00
fix: Attempt to better handle hook disposal (#1803)
- Use a Weak Concurrent Collection to track scoped hooks - Make `Hook`s remove themselves from the Tracked Hook list.
This commit is contained in:
parent
ee2c8dd9cc
commit
577977350f
8 changed files with 67 additions and 21 deletions
|
|
@ -20,6 +20,8 @@ public sealed class AsmHook : IDisposable, IDalamudHook
|
|||
private bool isEnabled = false;
|
||||
|
||||
private DynamicMethod statsMethod;
|
||||
|
||||
private Guid hookId = Guid.NewGuid();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AsmHook"/> class.
|
||||
|
|
@ -44,7 +46,7 @@ public sealed class AsmHook : IDisposable, IDalamudHook
|
|||
this.statsMethod.GetILGenerator().Emit(OpCodes.Ret);
|
||||
var dele = this.statsMethod.CreateDelegate(typeof(Action));
|
||||
|
||||
HookManager.TrackedHooks.TryAdd(Guid.NewGuid(), new HookInfo(this, dele, Assembly.GetCallingAssembly()));
|
||||
HookManager.TrackedHooks.TryAdd(this.hookId, new HookInfo(this, dele, Assembly.GetCallingAssembly()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -70,7 +72,7 @@ public sealed class AsmHook : IDisposable, IDalamudHook
|
|||
this.statsMethod.GetILGenerator().Emit(OpCodes.Ret);
|
||||
var dele = this.statsMethod.CreateDelegate(typeof(Action));
|
||||
|
||||
HookManager.TrackedHooks.TryAdd(Guid.NewGuid(), new HookInfo(this, dele, Assembly.GetCallingAssembly()));
|
||||
HookManager.TrackedHooks.TryAdd(this.hookId, new HookInfo(this, dele, Assembly.GetCallingAssembly()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -116,6 +118,8 @@ public sealed class AsmHook : IDisposable, IDalamudHook
|
|||
|
||||
this.IsDisposed = true;
|
||||
|
||||
HookManager.TrackedHooks.TryRemove(this.hookId, out _);
|
||||
|
||||
if (this.isEnabled)
|
||||
{
|
||||
this.isEnabled = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue