Prevent crash when game is corrupted.

This commit is contained in:
kekkon 2023-06-10 10:52:41 +02:00
parent 0e95a8271a
commit 8cf372243f
2 changed files with 30 additions and 8 deletions

View file

@ -650,5 +650,6 @@
"NetworkInterfaceDefault": "Default", "NetworkInterfaceDefault": "Default",
"PackagingShaders": "Packaging Shaders", "PackagingShaders": "Packaging Shaders",
"AboutChangelogButton": "View Changelog on GitHub", "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}"
} }

View file

@ -1480,10 +1480,29 @@ namespace Ryujinx.Ava.UI.ViewModels
async void Action() async void Action()
{ {
if (!await AppHost.LoadGuestApplication()) var loadSuccessful = false;
try
{ {
AppHost.DisposeContext(); loadSuccessful = await AppHost.LoadGuestApplication();
}
catch (HorizonResultException hex)
{
// Apphost Cleanup
AppHost = null; 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; return;
} }
@ -1505,7 +1524,7 @@ namespace Ryujinx.Ava.UI.ViewModels
Thread gameThread = new(InitializeGame) { Name = "GUI.WindowThread" }; Thread gameThread = new(InitializeGame) { Name = "GUI.WindowThread" };
gameThread.Start(); gameThread.Start();
} }
Dispatcher.UIThread.Post(Action); Dispatcher.UIThread.Post(Action);
} }
@ -1561,6 +1580,11 @@ namespace Ryujinx.Ava.UI.ViewModels
} }
public void AppHost_AppExit(object sender, EventArgs e) public void AppHost_AppExit(object sender, EventArgs e)
{
PostAppCleanup();
}
private void PostAppCleanup()
{ {
if (IsClosing) if (IsClosing)
{ {
@ -1590,10 +1614,7 @@ namespace Ryujinx.Ava.UI.ViewModels
SelectedIcon = null; SelectedIcon = null;
Dispatcher.UIThread.InvokeAsync(() => Dispatcher.UIThread.InvokeAsync(() => { Title = $"Ryujinx {Program.Version}"; });
{
Title = $"Ryujinx {Program.Version}";
});
} }
public void ToggleFullscreen() public void ToggleFullscreen()