From 3b2c4175fdfe84979faede9a01e6f73eb33bf9b9 Mon Sep 17 00:00:00 2001 From: HypherionMC Date: Wed, 2 Aug 2023 14:55:51 +0200 Subject: [PATCH] Error handling for failed launch Add proper error handling for instances that fail to launch, so that the launcher doesn't crash --- core/Launcher.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/Launcher.cs b/core/Launcher.cs index c6fb4b9..dd6b5fc 100644 --- a/core/Launcher.cs +++ b/core/Launcher.cs @@ -160,8 +160,24 @@ namespace WolfLauncher.core if (!String.IsNullOrEmpty(instance.settings.javaArgs)) options.JVMArguments = new string[] { instance.settings.javaArgs }; + Process process; + // Set up the launcher process - var process = await cmLauncher.CreateProcessAsync(parseLoader(instance), options, checkAndDownload: true); + try + { + process = await cmLauncher.CreateProcessAsync(parseLoader(instance), options, checkAndDownload: true); + } catch (Exception e) + { + MessageBox.Show(e.Message, "Failed to launch instance", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // Just a safety catch + if (process == null) + { + runningInstance = null; + return; + } // Setup console relay to log window process.OutputDataReceived += (s, e) =>