Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions scripts/DllManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ internal static void LoadTargetFunction(NativeFunction nativeFunction, bool igno
if (!ignoreLoadError)
{
dll.loadingError = true;
Prop_EditorApplication_isPaused.Value?.SetValue(null, true);
DispatchOnMainThread(() => { Prop_EditorApplication_isPaused.Value?.SetValue(null, true); });
throw new NativeDllException($"Could not load DLL \"{dll.name}\" at path \"{dll.path}\".");
}

Expand All @@ -529,7 +529,7 @@ internal static void LoadTargetFunction(NativeFunction nativeFunction, bool igno
if (!ignoreLoadError)
{
dll.symbolError = true;
Prop_EditorApplication_isPaused.Value?.SetValue(null, true);
DispatchOnMainThread(() => { Prop_EditorApplication_isPaused.Value?.SetValue(null, true); });
throw new NativeDllException($"Could not get address of symbol \"{nativeFunction.identity.symbol}\" in DLL \"{dll.name}\" at path \"{dll.path}\".");
}

Expand Down Expand Up @@ -568,6 +568,18 @@ private static void InvokeCustomTriggers(List<Tuple<MethodInfo, bool>> triggers,
methodInfo.Invoke(null, args);
}
}

/// <summary>
/// Ensure the action is executed on the main thread. Executes immediately if on the main thread already,
/// otherwise the action is added to a queue <see cref="DllManipulatorScript.MainThreadTriggerQueue"/>
/// </summary>
private static void DispatchOnMainThread(Action action)
{
if(Thread.CurrentThread.ManagedThreadId == _unityMainThreadId)
action();
else
DllManipulatorScript.MainThreadTriggerQueue.Enqueue(action);
}

/// <summary>
/// Logs native function's call to file. If that file exists, it is overwritten. One file is maintained for each thread.
Expand Down