From fd70c031cba8683ebc91666f66fd373b1e4d05d9 Mon Sep 17 00:00:00 2001 From: "Ram.Type-0" Date: Tue, 24 Nov 2020 23:50:01 +0900 Subject: [PATCH] Force complete awaiting JobHandles when quitted in UnityEditor --- .../Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs | 4 +++- .../Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs index ba06ddd..508e24e 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs @@ -101,7 +101,7 @@ namespace Cysharp.Threading.Tasks static SynchronizationContext unitySynchronizationContetext; static ContinuationQueue[] yielders; static PlayerLoopRunner[] runners; - + internal static bool IsEditorApplicationQuitting { get; private set; } static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType, ContinuationQueue cq, Type lastLoopRunnerYieldType, ContinuationQueue lastCq, Type loopRunnerType, PlayerLoopRunner runner, Type lastLoopRunnerType, PlayerLoopRunner lastRunner) @@ -112,6 +112,7 @@ namespace Cysharp.Threading.Tasks { if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.ExitingEditMode) { + IsEditorApplicationQuitting = true; // run rest action before clear. if (runner != null) { @@ -134,6 +135,7 @@ namespace Cysharp.Threading.Tasks lastCq.Run(); lastCq.Clear(); } + IsEditorApplicationQuitting = false; } }; #endif diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs index a5dafb8..db0a892 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using Unity.Jobs; +using UnityEngine; namespace Cysharp.Threading.Tasks { @@ -85,7 +86,7 @@ namespace Cysharp.Threading.Tasks public bool MoveNext() { - if (jobHandle.IsCompleted) + if (jobHandle.IsCompleted | PlayerLoopHelper.IsEditorApplicationQuitting) { jobHandle.Complete(); core.TrySetResult(AsyncUnit.Default);