Skip to content

Commit 4632960

Browse files
committed
SyncContextUtil: fix initialization in Edit Mode
As described modesttree#9, using Unity3dAsyncAwaitUtil in Editor scripts causes an NPE, because `SyncContextUtil.Install` is never called to initialize global variables `SyncContextUtil.UnitySynchronizationContext` and `SyncContextUtil.UnityThreadId`. Fix this by adding the `[InitializeOnLoadMethod()]` attribute to the `SyncContextUtil.Install` method. Note that the existing `[RuntimeInitializeOnLoadMethod]` attribute is still needed in order for `SyncContextUtil.Install` to be correctly invoked in Play Mode. Fixes modesttree#9
1 parent 5f948fd commit 4632960

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

UnityProject/Assets/Plugins/AsyncAwaitUtil/Source/Internal/SyncContextUtil.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
using System.Threading.Tasks;
77
using UnityEngine;
88

9+
#if UNITY_EDITOR
10+
using UnityEditor;
11+
#endif
12+
913
namespace UnityAsyncAwaitUtil
1014
{
1115
public static class SyncContextUtil
1216
{
17+
#if UNITY_EDITOR
18+
[InitializeOnLoadMethod()]
19+
#endif
1320
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
1421
static void Install()
1522
{

0 commit comments

Comments
 (0)