From 8cf372243f1070187c8e8c14f6cdd4e7360d5f35 Mon Sep 17 00:00:00 2001 From: kekkon Date: Sat, 10 Jun 2023 10:52:41 +0200 Subject: [PATCH] Prevent crash when game is corrupted. --- src/Ryujinx.Ava/Assets/Locales/en_US.json | 3 +- .../UI/ViewModels/MainWindowViewModel.cs | 35 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json index 4065a1dfb..294d3e0a1 100644 --- a/src/Ryujinx.Ava/Assets/Locales/en_US.json +++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json @@ -650,5 +650,6 @@ "NetworkInterfaceDefault": "Default", "PackagingShaders": "Packaging Shaders", "AboutChangelogButton": "View Changelog on GitHub", - "AboutChangelogButtonTooltipMessage": "Click to open the changelog for this version in your default browser." + "AboutChangelogButtonTooltipMessage": "Click to open the changelog for this version in your default browser.", + "DialogCorruptedGameError": "It appears this game is corrupted. Please dump the game again.\nInternal error code: {0}" } \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs index 409ccad3c..21373d5e7 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs @@ -1480,10 +1480,29 @@ namespace Ryujinx.Ava.UI.ViewModels async void Action() { - if (!await AppHost.LoadGuestApplication()) + var loadSuccessful = false; + try { - AppHost.DisposeContext(); + loadSuccessful = await AppHost.LoadGuestApplication(); + } + catch (HorizonResultException hex) + { + // Apphost Cleanup AppHost = null; + SelectedIcon = null; + + await Dispatcher.UIThread.InvokeAsync(async () => + { + await ContentDialogHelper.CreateErrorDialog( + string.Format(LocaleManager.Instance[LocaleKeys.DialogCorruptedGameError], hex.Message)); + }); + + return; + } + + if (!loadSuccessful) + { + PostAppCleanup(); return; } @@ -1505,7 +1524,7 @@ namespace Ryujinx.Ava.UI.ViewModels Thread gameThread = new(InitializeGame) { Name = "GUI.WindowThread" }; gameThread.Start(); } - + Dispatcher.UIThread.Post(Action); } @@ -1561,6 +1580,11 @@ namespace Ryujinx.Ava.UI.ViewModels } public void AppHost_AppExit(object sender, EventArgs e) + { + PostAppCleanup(); + } + + private void PostAppCleanup() { if (IsClosing) { @@ -1590,10 +1614,7 @@ namespace Ryujinx.Ava.UI.ViewModels SelectedIcon = null; - Dispatcher.UIThread.InvokeAsync(() => - { - Title = $"Ryujinx {Program.Version}"; - }); + Dispatcher.UIThread.InvokeAsync(() => { Title = $"Ryujinx {Program.Version}"; }); } public void ToggleFullscreen()