Cleanup fixes

pull/14/head
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,9 +240,10 @@ namespace MoonWorks.Audio
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
foreach (var weakReference in streamingSounds)
for (var i = streamingSounds.Count - 1; i >= 0; i--)
{
var weakReference = streamingSounds[i];
if (weakReference.TryGetTarget(out var streamingSound))
{
streamingSound.Dispose();
@ -251,6 +252,8 @@ namespace MoonWorks.Audio
streamingSounds.Clear();
}
FAudio.FAudioVoice_DestroyVoice(ReverbVoice);
FAudio.FAudioVoice_DestroyVoice(MasteringVoice);
FAudio.FAudio_Release(Handle);
IsDisposed = true;

View File

@ -139,7 +139,13 @@ namespace MoonWorks
GraphicsDevice.SubmitDestroyCommandBuffer();
}
OnDestroy();
AudioDevice.Dispose();
GraphicsDevice.Dispose();
Window.Dispose();
SDL.SDL_Quit();
}
private void HandleSDLEvents()
@ -168,6 +174,9 @@ namespace MoonWorks
// alpha refers to a percentage value between the current and next state
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)
{
// Based on the SDL2# LPUtf8StrMarshaler

View File

@ -3,11 +3,13 @@ using SDL2;
namespace MoonWorks.Window
{
public class OSWindow
public class OSWindow : IDisposable
{
internal IntPtr Handle { get; }
public ScreenMode ScreenMode { get; }
private bool IsDisposed;
public OSWindow(WindowCreateInfo windowCreateInfo)
{
var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN;
@ -59,5 +61,33 @@ namespace MoonWorks.Window
{
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);
}
}
}