diff --git a/Program.cs b/Program.cs index df1e7c5ab3..88253bc61b 100644 --- a/Program.cs +++ b/Program.cs @@ -50,6 +50,10 @@ namespace Ryujinx using (GLScreen Screen = new GLScreen(Ns, Renderer)) { + Ns.Finish += (Sender, Args) => { + Screen.Exit(); + }; + Screen.Run(60.0); } diff --git a/Ryujinx/OsHle/Horizon.cs b/Ryujinx/OsHle/Horizon.cs index 04744bdfac..f94fa42044 100644 --- a/Ryujinx/OsHle/Horizon.cs +++ b/Ryujinx/OsHle/Horizon.cs @@ -4,6 +4,7 @@ using Ryujinx.OsHle.Handles; using Ryujinx.OsHle.Utilities; using System.Collections.Concurrent; using System.IO; +using System; namespace Ryujinx.OsHle { @@ -135,6 +136,18 @@ namespace Ryujinx.OsHle } } + internal bool ExitProcess(int ProcessId) { + Process process; + var Success = Processes.TryRemove(ProcessId, out process); + if (Success) { + process.StopAllThreads(); + } + + if (Processes.Count == 0) { + Ns.OnFinish(EventArgs.Empty); + } + return Success; + } internal bool TryGetProcess(int ProcessId, out Process Process) { if (!Processes.TryGetValue(ProcessId, out Process)) diff --git a/Ryujinx/OsHle/Process.cs b/Ryujinx/OsHle/Process.cs index 6682384687..59b450c115 100644 --- a/Ryujinx/OsHle/Process.cs +++ b/Ryujinx/OsHle/Process.cs @@ -104,7 +104,7 @@ namespace Ryujinx.OsHle { if (MainThread != null) { - while (MainThread.IsAlive) + if (MainThread.IsAlive) { MainThread.StopExecution(); } @@ -112,7 +112,7 @@ namespace Ryujinx.OsHle foreach (AThread Thread in TlsSlots.Values) { - while (Thread.IsAlive) + if (Thread.IsAlive) { Thread.StopExecution(); } diff --git a/Ryujinx/OsHle/Svc/SvcSystem.cs b/Ryujinx/OsHle/Svc/SvcSystem.cs index 084b01fe89..116f8c0a19 100644 --- a/Ryujinx/OsHle/Svc/SvcSystem.cs +++ b/Ryujinx/OsHle/Svc/SvcSystem.cs @@ -10,7 +10,7 @@ namespace Ryujinx.OsHle.Svc { private static void SvcExitProcess(Switch Ns, ARegisters Registers, AMemory Memory) { - Environment.Exit(0); + Ns.Os.ExitProcess(Registers.ProcessId); } private static void SvcCloseHandle(Switch Ns, ARegisters Registers, AMemory Memory) diff --git a/Ryujinx/Switch.cs b/Ryujinx/Switch.cs index 9e5ea7d06c..e912da86b3 100644 --- a/Ryujinx/Switch.cs +++ b/Ryujinx/Switch.cs @@ -24,6 +24,15 @@ namespace Ryujinx VFs = new VirtualFs(); } + public event EventHandler Finish; + internal virtual void OnFinish(EventArgs e) + { + EventHandler Handler = Finish; + if (Handler != null) + { + Handler(this, e); + } + } public void Dispose() { Dispose(true);