Fix CA2216

This commit is contained in:
RoosterDragon
2023-03-13 18:31:04 +00:00
committed by abcdefg30
parent a120b9d37e
commit f470f9ab91
3 changed files with 25 additions and 5 deletions

View File

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

View File

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

View File

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