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",
"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}"
}

View file

@ -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()