diff --git a/CHANGELOG.md b/CHANGELOG.md
index fcb21e84..8c7a1fa0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,10 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
### Fixed
+- [#507] Fixed a potential editor freeze bug
### Changed
### Removed
+- [#507] Removed the `NDMFSyncContext.RunOnMainThread` API which was accidentally addded in 1.6.3.
+ This might be re-added in 1.7.0.
### Security
diff --git a/Editor/PreviewSystem/ComputeContext.cs b/Editor/PreviewSystem/ComputeContext.cs
index 6d3a8fde..8a581ec1 100644
--- a/Editor/PreviewSystem/ComputeContext.cs
+++ b/Editor/PreviewSystem/ComputeContext.cs
@@ -145,7 +145,7 @@ public ComputeContext(string description)
arg0: this
).EventId;
- TaskUtil.OnMainThread(this, DoInvalidate);
+ NDMFSyncContext.RunOnMainThread(target => DoInvalidate((ComputeContext)target), this);
};
Description = description;
diff --git a/Editor/PreviewSystem/Task/NDMFSyncContext.cs b/Editor/PreviewSystem/Task/NDMFSyncContext.cs
index 6cc60904..59c4a668 100644
--- a/Editor/PreviewSystem/Task/NDMFSyncContext.cs
+++ b/Editor/PreviewSystem/Task/NDMFSyncContext.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
+using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
@@ -15,20 +16,23 @@ public static class NDMFSyncContext
{
public static SynchronizationContext Context = new Impl();
private static Impl InternalContext = (Impl)Context;
-
+
///
- /// Runs the given function on the unity main thread - synchronously if possible.
+ /// Runs the given function on the unity main thread, passing the given target as an argument.
+ /// The function will be invoked synchronously if called from the main thread; otherwise, it will be
+ /// run asynchronously.
///
- ///
- public static void RunOnMainThread(EditorApplication.CallbackFunction cb)
+ ///
+ ///
+ internal static void RunOnMainThread(SendOrPostCallback receiver, object target)
{
if (Thread.CurrentThread.ManagedThreadId == InternalContext.unityMainThreadId)
{
- cb();
+ receiver(target);
}
else
{
- Context.Send(_ => cb(), null);
+ Context.Post(receiver, target);
}
}
diff --git a/Editor/PreviewSystem/TaskUtil.cs b/Editor/PreviewSystem/TaskUtil.cs
index 39d14ca6..3cc1c5e0 100644
--- a/Editor/PreviewSystem/TaskUtil.cs
+++ b/Editor/PreviewSystem/TaskUtil.cs
@@ -13,10 +13,5 @@ static void Init()
{
_mainThread = Thread.CurrentThread;
}
-
- internal static void OnMainThread(T target, Action receiver)
- {
- NDMFSyncContext.RunOnMainThread(() => receiver(target));
- }
}
}
\ No newline at end of file