diff --git a/.editorconfig b/.editorconfig index 3a7edd5f42..fa7e52cd49 100644 --- a/.editorconfig +++ b/.editorconfig @@ -825,6 +825,9 @@ dotnet_diagnostic.CA2208.severity = warning # Dispose methods should call base class dispose. dotnet_diagnostic.CA2215.severity = warning +# Disposable types should declare finalizer. +dotnet_diagnostic.CA2216.severity = warning + # Override GetHashCode on overriding Equals. dotnet_diagnostic.CA2218.severity = warning diff --git a/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs b/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs index 06cf97b443..67ea0ad6fc 100644 --- a/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs +++ b/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs @@ -19,9 +19,10 @@ namespace OpenRA.Platforms.Default sealed class Sdl2GraphicsContext : ThreadAffine, IGraphicsContext { readonly Sdl2PlatformWindow window; - bool disposed; IntPtr context; + public string GLVersion => OpenGL.Version; + public Sdl2GraphicsContext(Sdl2PlatformWindow window) { this.window = window; @@ -269,10 +270,12 @@ namespace OpenRA.Platforms.Default public void Dispose() { - if (disposed) - return; + Dispose(true); + GC.SuppressFinalize(this); + } - disposed = true; + void Dispose(bool _) + { if (context != IntPtr.Zero) { SDL.SDL_GL_DeleteContext(context); @@ -280,6 +283,9 @@ namespace OpenRA.Platforms.Default } } - public string GLVersion => OpenGL.Version; + ~Sdl2GraphicsContext() + { + Dispose(false); + } } } diff --git a/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs b/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs index 7ab937970a..f34b6f5ab1 100644 --- a/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs +++ b/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs @@ -45,6 +45,12 @@ namespace OpenRA.Platforms.Default } public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + void Dispose(bool _) { if (Cursor != IntPtr.Zero) { @@ -58,5 +64,10 @@ namespace OpenRA.Platforms.Default surface = IntPtr.Zero; } } + + ~Sdl2HardwareCursor() + { + Dispose(false); + } } }