Merge pull request #196 from RamType0/ForceCompleteJobHandleOnApplicationQuit

Force complete awaiting JobHandles when quitted in UnityEditor
master
Yoshifumi Kawai 2020-11-25 09:00:21 +09:00 committed by GitHub
commit 3115efb672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -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

View File

@ -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);