diff --git a/InteropDLL/EmuApiWrapper.cpp b/InteropDLL/EmuApiWrapper.cpp index 44251e9..5b1877d 100644 --- a/InteropDLL/EmuApiWrapper.cpp +++ b/InteropDLL/EmuApiWrapper.cpp @@ -153,9 +153,13 @@ extern "C" { _console->Resume(); } - DllExport void __stdcall IsPaused() + DllExport bool __stdcall IsPaused() { - _console->IsPaused(); + shared_ptr console = _console; + if(console) { + return console->IsPaused(); + } + return true; } DllExport void __stdcall Reset() diff --git a/UI/Forms/frmMain.cs b/UI/Forms/frmMain.cs index c5c53aa..cfb54a3 100644 --- a/UI/Forms/frmMain.cs +++ b/UI/Forms/frmMain.cs @@ -97,24 +97,38 @@ namespace Mesen.GUI.Forms this.Resize += frmMain_Resize; } + private bool _shuttingDown = false; protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); - DebugApi.ResumeExecution(); - DebugWindowManager.CloseAll(); - - EmuApi.Stop(); + InBackgroundHelper.StopBackgroundTimer(); if(_notifListener != null) { _notifListener.Dispose(); _notifListener = null; } + if(!_shuttingDown && Program.IsMono) { + //This appears to prevent Mono from locking up when closing the form + DebugApi.ResumeExecution(); + DebugWindowManager.CloseAll(); + + Task.Run(() => { + EmuApi.Stop(); + _shuttingDown = true; + this.BeginInvoke((Action)(() => this.Close())); + }); + e.Cancel = true; + return; + } + ConfigManager.Config.WindowLocation = this.WindowState == FormWindowState.Normal ? this.Location : this.RestoreBounds.Location; ConfigManager.Config.WindowSize = this.WindowState == FormWindowState.Normal ? this.Size : this.RestoreBounds.Size; ConfigManager.ApplyChanges(); + ConfigManager.SaveConfig(); + EmuApi.Stop(); EmuApi.Release(); }