From e68e861ec7b7b649802e9a767a0fd09566ac9b54 Mon Sep 17 00:00:00 2001 From: starfish <50672801+starfi5h@users.noreply.github.com> Date: Tue, 11 Jun 2024 12:53:16 +0800 Subject: [PATCH] Fix IsNgrokActive crash when calling Log.Error on non-main thread --- NebulaModel/Logger/Log.cs | 9 +++++++++ NebulaNetwork/Ngrok/NgrokManager.cs | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NebulaModel/Logger/Log.cs b/NebulaModel/Logger/Log.cs index fa7c93d48..f2e187a54 100644 --- a/NebulaModel/Logger/Log.cs +++ b/NebulaModel/Logger/Log.cs @@ -66,6 +66,15 @@ public static void Error(string message) LastErrorMsg = message; if (UIFatalErrorTip.instance != null) { + // Test if current code is executing on the main unity thread + if (BepInEx.ThreadingHelper.Instance.InvokeRequired) + { + // ShowError has Unity API and needs to call on the main thread + BepInEx.ThreadingHelper.Instance.StartSyncInvoke(() => + UIFatalErrorTip.instance.ShowError("[Nebula Error] " + message, "") + ); + return; + } UIFatalErrorTip.instance.ShowError("[Nebula Error] " + message, ""); } } diff --git a/NebulaNetwork/Ngrok/NgrokManager.cs b/NebulaNetwork/Ngrok/NgrokManager.cs index fc1b11da8..f92837681 100644 --- a/NebulaNetwork/Ngrok/NgrokManager.cs +++ b/NebulaNetwork/Ngrok/NgrokManager.cs @@ -298,9 +298,8 @@ public bool IsNgrokActive() _ngrokProcess?.Refresh(); return !_ngrokProcess?.HasExited ?? false; } - catch (Exception e) + catch { - Log.Error(e); return false; } }