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) if (rtm is null)
return false; return false;
if (!ThreadSafety.IsMainThread) ThreadSafety.AssertMainThread("Global parameters may only be used from the main thread.");
{
Log.Error("Global parameters may only be used from the main thread.");
return false;
}
ref var gp = ref rtm->TextModule.MacroDecoder.GlobalParameters; ref var gp = ref rtm->TextModule.MacroDecoder.GlobalParameters;
if (parameterIndex >= gp.MySize) if (parameterIndex >= gp.MySize)

View file

@ -18,13 +18,14 @@ public static class ThreadSafety
/// <summary> /// <summary>
/// Throws an exception when the current thread is not the main thread. /// Throws an exception when the current thread is not the main thread.
/// </summary> /// </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> /// <exception cref="InvalidOperationException">Thrown when the current thread is not the main thread.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AssertMainThread() public static void AssertMainThread(string? message = null)
{ {
if (!threadStaticIsMainThread) if (!threadStaticIsMainThread)
{ {
throw new InvalidOperationException("Not on main thread!"); throw new InvalidOperationException(message ?? "Not on main thread!");
} }
} }