SeStringEvaluator: Throw if not on main thread

This commit is contained in:
goaaats 2025-03-24 20:23:56 +01:00
parent 84f5dad0a3
commit f209ac087a
2 changed files with 4 additions and 7 deletions

View file

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

View file

@ -18,13 +18,14 @@ public static class ThreadSafety
/// <summary>
/// Throws an exception when the current thread is not the main thread.
/// </summary>
/// <param name="message">The message to be passed into the exception, if one is to be thrown.</param>
/// <exception cref="InvalidOperationException">Thrown when the current thread is not the main thread.</exception>
[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!");
}
}