From 5d336981c6e51360c708798730c2ee4058d830be Mon Sep 17 00:00:00 2001 From: Jeremy Lu Date: Mon, 10 Aug 2026 10:51:05 -0700 Subject: [PATCH] Show an error dialog when the game fails to launch Profile.RunGame never checked the child process's exit code, so if the game binary crashed immediately (e.g. a missing shared library), the launcher silently returned to the main screen with no feedback, even though the failure reason was already being written to the profile's log file. RunGame now throws when the process exits with a non-zero code, and the Play button handler shows that in an error dialog instead of swallowing it. Co-Authored-By: Claude Sonnet 5 --- AM2RLauncher/AM2RLauncher/Language/Text.Designer.cs | 6 ++++++ AM2RLauncher/AM2RLauncher/Language/Text.resx | 3 +++ .../AM2RLauncher/MainForm/MainForm.Events.cs | 3 ++- AM2RLauncher/AM2RLauncherLib/Profile.cs | 12 ++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/AM2RLauncher/AM2RLauncher/Language/Text.Designer.cs b/AM2RLauncher/AM2RLauncher/Language/Text.Designer.cs index b638895..5bcdad7 100644 --- a/AM2RLauncher/AM2RLauncher/Language/Text.Designer.cs +++ b/AM2RLauncher/AM2RLauncher/Language/Text.Designer.cs @@ -207,6 +207,12 @@ namespace AM2RLauncher.Language { } } + public static string GameLaunchFailed { + get { + return ResourceManager.GetString("GameLaunchFailed", resourceCulture); + } + } + public static string GithubToolTip { get { return ResourceManager.GetString("GithubToolTip", resourceCulture); diff --git a/AM2RLauncher/AM2RLauncher/Language/Text.resx b/AM2RLauncher/AM2RLauncher/Language/Text.resx index f993610..c36fff5 100644 --- a/AM2RLauncher/AM2RLauncher/Language/Text.resx +++ b/AM2RLauncher/AM2RLauncher/Language/Text.resx @@ -198,6 +198,9 @@ Error + + The game failed to launch. + The Community-Developers GitHub Page diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs index e5a3e23..ab85a88 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs @@ -469,7 +469,8 @@ public partial class MainForm : Form } catch (Exception ex) { - MessageBox.Show($"{Text.UnhandledException}\n*****Stack Trace*****\n\n{ex}", Text.ErrorWindowTitle, MessageBoxType.Error); + log.Error(ex.Message); + MessageBox.Show($"{Text.GameLaunchFailed}\n\n{ex.Message}", Text.ErrorWindowTitle, MessageBoxType.Error); } ShowInTaskbar = true; diff --git a/AM2RLauncher/AM2RLauncherLib/Profile.cs b/AM2RLauncher/AM2RLauncherLib/Profile.cs index fc116d8..8b5818c 100644 --- a/AM2RLauncher/AM2RLauncherLib/Profile.cs +++ b/AM2RLauncher/AM2RLauncherLib/Profile.cs @@ -738,6 +738,7 @@ public static class Profile string gameDirectory = $"{Core.ProfilesPath}/{profile.Name}"; log.Info($"Launching game profile {profile.Name}."); + int exitCode = 0; if (OS.IsWindows) { // Sets the arguments to empty, or to the profiles' logs folder to create time based logs. @@ -777,6 +778,7 @@ public static class Profile process.Start(); Core.SetForegroundWindow(process.MainWindowHandle); process.WaitForExit(); + exitCode = process.ExitCode; } else if (OS.IsLinux) { @@ -847,6 +849,7 @@ public static class Profile process.BeginErrorReadLine(); } process.WaitForExit(); + exitCode = process.ExitCode; } else if (OS.IsMac) { @@ -882,10 +885,19 @@ public static class Profile using Process process = new Process { StartInfo = processStartInfo }; process.Start(); process.WaitForExit(); + exitCode = process.ExitCode; } else log.Error($"{OS.Name} cannot run games!"); log.Info($"Profile {profile.Name} process exited."); + + if (exitCode != 0) + { + string message = $"Game process for profile \"{profile.Name}\" exited with code {exitCode}, it likely failed to launch."; + if (useLogging) + message += $" Check the log file for more details: {logFile}"; + throw new Exception(message); + } } }