diff --git a/Intersect.Client.Core/Maps/WeatherParticle.cs b/Intersect.Client.Core/Maps/WeatherParticle.cs index 8d9f4f14fd..cbe4186b60 100644 --- a/Intersect.Client.Core/Maps/WeatherParticle.cs +++ b/Intersect.Client.Core/Maps/WeatherParticle.cs @@ -11,36 +11,34 @@ namespace Intersect.Client.Maps; - -public partial class WeatherParticle : IWeatherParticle +public partial class WeatherParticle : IWeatherParticle, IDisposable { + private readonly List _RemoveParticle; - private List _RemoveParticle; + private readonly Animation animInstance; - private Animation animInstance; + private readonly Rectangle bounds; - private Rectangle bounds; + private readonly float cameraSpawnX; - private float cameraSpawnX; + private readonly float cameraSpawnY; - private float cameraSpawnY; + private readonly int originalX; - private int originalX; + private readonly int originalY; - private int originalY; + private readonly Point partSize; - private Point partSize; + private readonly long TransmittionTimer; - private long TransmittionTimer; + private readonly int xVelocity; - public float X { get; set; } + private readonly int yVelocity; - private int xVelocity; + public float X { get; set; } public float Y { get; set; } - private int yVelocity; - public WeatherParticle(List RemoveParticle, int xvelocity, int yvelocity, AnimationDescriptor anim) { TransmittionTimer = Timing.Global.MillisecondsUtc; @@ -136,6 +134,10 @@ public void Update() if (!newBounds.IntersectsWith(new Rectangle((int)X, (int)Y, partSize.X, partSize.Y))) { + if (_RemoveParticle.Contains(this)) + { + throw new Exception(); + } _RemoveParticle.Add(this); } else @@ -150,12 +152,34 @@ public void Update() public void Dispose() { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + ReleaseUnmanagedResources(); + + if (!disposing) + { + return; + } + animInstance.Dispose(); + ReleaseManagedResources(); } - ~WeatherParticle() + protected virtual void ReleaseManagedResources() + { + } + + protected virtual void ReleaseUnmanagedResources() { - Dispose(); + // TODO release unmanaged resources here } + ~WeatherParticle() + { + Dispose(false); + } }