Fixed IDisposable implementation and usage.

- Implement IDisposable interface correctly, with sealed classes where possible for simplicity.
- Add using statement around undisposed local variables.
This commit is contained in:
RoosterDragon
2014-05-21 06:19:26 +01:00
parent 334a210231
commit a598a01108
37 changed files with 248 additions and 260 deletions

View File

@@ -29,11 +29,12 @@ namespace OpenRA.Renderer.Sdl2
}
}
public class Sdl2GraphicsDevice : IGraphicsDevice
public sealed class Sdl2GraphicsDevice : IGraphicsDevice
{
Size size;
Sdl2Input input;
IntPtr context, window;
bool disposed;
public Size WindowSize { get { return size; } }
@@ -98,10 +99,21 @@ namespace OpenRA.Renderer.Sdl2
input = new Sdl2Input();
}
public virtual void Quit()
public void Dispose()
{
SDL.SDL_GL_DeleteContext(context);
SDL.SDL_DestroyWindow(window);
if (disposed)
return;
disposed = true;
if (context != IntPtr.Zero)
{
SDL.SDL_GL_DeleteContext(context);
context = IntPtr.Zero;
}
if (window != IntPtr.Zero)
{
SDL.SDL_DestroyWindow(window);
window = IntPtr.Zero;
}
SDL.SDL_Quit();
}