From f209ac087af3dee6d9e5b50efadfb3c9e0813ba5 Mon Sep 17 00:00:00 2001 From: goaaats Date: Mon, 24 Mar 2025 20:23:56 +0100 Subject: [PATCH] SeStringEvaluator: Throw if not on main thread --- Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs | 6 +----- Dalamud/Utility/ThreadSafety.cs | 5 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs b/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs index 723dbcb41..eb6dee290 100644 --- a/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs +++ b/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs @@ -1682,11 +1682,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator if (rtm is null) return false; - if (!ThreadSafety.IsMainThread) - { - Log.Error("Global parameters may only be used from the main thread."); - return false; - } + ThreadSafety.AssertMainThread("Global parameters may only be used from the main thread."); ref var gp = ref rtm->TextModule.MacroDecoder.GlobalParameters; if (parameterIndex >= gp.MySize) diff --git a/Dalamud/Utility/ThreadSafety.cs b/Dalamud/Utility/ThreadSafety.cs index ea8238d44..c31cc0005 100644 --- a/Dalamud/Utility/ThreadSafety.cs +++ b/Dalamud/Utility/ThreadSafety.cs @@ -18,13 +18,14 @@ public static class ThreadSafety /// /// Throws an exception when the current thread is not the main thread. /// + /// The message to be passed into the exception, if one is to be thrown. /// Thrown when the current thread is not the main thread. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void AssertMainThread() + public static void AssertMainThread(string? message = null) { if (!threadStaticIsMainThread) { - throw new InvalidOperationException("Not on main thread!"); + throw new InvalidOperationException(message ?? "Not on main thread!"); } }