fix: Codegens talismans - Fixes memory leak (#1469)

This commit is contained in:
Kamron Batman 2023-08-23 22:41:48 -07:00 • committed by GitHub
parent ca89b8b08b
commit ffb0b24e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 1979 additions and 2256 deletions

View file

@ -10,6 +10,7 @@ public class UnsummonTimer : Timer
// Track timers since some of them are really long and might hold references to long dead/deleted mobs
private static readonly Dictionary<BaseCreature, UnsummonTimer> _timers = new();
private BaseCreature _creature;
private Action _onUnsummon;
public static void StopTimer(BaseCreature creature)
{
@ -19,8 +20,9 @@ public class UnsummonTimer : Timer
}
}
public UnsummonTimer(BaseCreature creature, TimeSpan delay) : base(delay)
public UnsummonTimer(BaseCreature creature, TimeSpan delay, Action onUnsummon = null) : base(delay)
{
_onUnsummon = onUnsummon;
_creature = creature;
ref var timer = ref CollectionsMarshal.GetValueRefOrAddDefault(_timers, creature, out bool exists);
@ -36,5 +38,6 @@ public class UnsummonTimer : Timer
{
// BaseCreature.OnAfterDelete will remove the creature from the timers table
_creature?.Delete();
_onUnsummon?.Invoke();
}
}