forked from MoonsideGames/MoonWorks
Cleanup fixes
parent
5679dba978
commit
a0c57c7a59
|
@ -240,17 +240,20 @@ namespace MoonWorks.Audio
|
|||
{
|
||||
if (disposing)
|
||||
{
|
||||
// TODO: dispose managed state (managed objects)
|
||||
foreach (var weakReference in streamingSounds)
|
||||
{
|
||||
if (weakReference.TryGetTarget(out var streamingSound))
|
||||
for (var i = streamingSounds.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var weakReference = streamingSounds[i];
|
||||
|
||||
if (weakReference.TryGetTarget(out var streamingSound))
|
||||
{
|
||||
streamingSound.Dispose();
|
||||
}
|
||||
}
|
||||
streamingSounds.Clear();
|
||||
}
|
||||
streamingSounds.Clear();
|
||||
}
|
||||
|
||||
FAudio.FAudioVoice_DestroyVoice(ReverbVoice);
|
||||
FAudio.FAudioVoice_DestroyVoice(MasteringVoice);
|
||||
FAudio.FAudio_Release(Handle);
|
||||
|
||||
IsDisposed = true;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,11 +3,13 @@ using SDL2;
|
|||
|
||||
namespace MoonWorks.Window
|
||||
{
|
||||
public class OSWindow
|
||||
public class OSWindow : IDisposable
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue