Cleanup fixes

main
cosmonaut 2022-02-22 16:44:39 -08:00
parent 5679dba978
commit a0c57c7a59
3 changed files with 51 additions and 9 deletions

View File

@ -240,17 +240,20 @@ namespace MoonWorks.Audio
{ {
if (disposing) if (disposing)
{ {
// TODO: dispose managed state (managed objects) for (var i = streamingSounds.Count - 1; i >= 0; i--)
foreach (var weakReference in streamingSounds) {
{ var weakReference = streamingSounds[i];
if (weakReference.TryGetTarget(out var streamingSound))
if (weakReference.TryGetTarget(out var streamingSound))
{ {
streamingSound.Dispose(); streamingSound.Dispose();
} }
} }
streamingSounds.Clear(); streamingSounds.Clear();
} }
FAudio.FAudioVoice_DestroyVoice(ReverbVoice);
FAudio.FAudioVoice_DestroyVoice(MasteringVoice);
FAudio.FAudio_Release(Handle); FAudio.FAudio_Release(Handle);
IsDisposed = true; IsDisposed = true;

View File

@ -139,7 +139,13 @@ namespace MoonWorks
GraphicsDevice.SubmitDestroyCommandBuffer(); GraphicsDevice.SubmitDestroyCommandBuffer();
} }
OnDestroy();
AudioDevice.Dispose();
GraphicsDevice.Dispose(); GraphicsDevice.Dispose();
Window.Dispose();
SDL.SDL_Quit();
} }
private void HandleSDLEvents() private void HandleSDLEvents()
@ -168,6 +174,9 @@ namespace MoonWorks
// alpha refers to a percentage value between the current and next state // alpha refers to a percentage value between the current and next state
protected abstract void Draw(TimeSpan dt, double alpha); protected abstract void Draw(TimeSpan dt, double alpha);
// Clean up any objects you created in this function
protected abstract void OnDestroy();
private void HandleTextInput(SDL2.SDL.SDL_Event evt) private void HandleTextInput(SDL2.SDL.SDL_Event evt)
{ {
// Based on the SDL2# LPUtf8StrMarshaler // Based on the SDL2# LPUtf8StrMarshaler

View File

@ -3,11 +3,13 @@ using SDL2;
namespace MoonWorks.Window namespace MoonWorks.Window
{ {
public class OSWindow public class OSWindow : IDisposable
{ {
internal IntPtr Handle { get; } internal IntPtr Handle { get; }
public ScreenMode ScreenMode { get; } public ScreenMode ScreenMode { get; }
private bool IsDisposed;
public OSWindow(WindowCreateInfo windowCreateInfo) public OSWindow(WindowCreateInfo windowCreateInfo)
{ {
var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN; var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN;
@ -59,5 +61,33 @@ namespace MoonWorks.Window
{ {
SDL.SDL_SetWindowSize(Handle, (int)width, (int)height); SDL.SDL_SetWindowSize(Handle, (int)width, (int)height);
} }
}
protected virtual void Dispose(bool disposing)
{
if (!IsDisposed)
{
if (disposing)
{
// dispose managed state (managed objects)
}
SDL.SDL_DestroyWindow(Handle);
IsDisposed = true;
}
}
~OSWindow()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: false);
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
} }