From bdd569e213cd830b5df7d1b4de3ded686b1d62ce Mon Sep 17 00:00:00 2001 From: neuecc Date: Wed, 17 Jun 2020 21:37:45 +0900 Subject: [PATCH] fix can not close application in mono build --- .../UniTask/Runtime/AsyncReactiveProperty.cs | 16 --- .../CompilerServices/StateMachineRunner.cs | 16 --- .../Runtime/EnumeratorAsyncExtensions.cs | 8 -- .../External/AddressableAsyncExtensions.cs | 32 ----- .../External/DoTweenAsyncExtensions.cs | 8 -- .../Plugins/UniTask/Runtime/UniTask.Delay.cs | 41 +------ .../UniTask/Runtime/UniTask.WaitUntil.cs | 40 ------ .../Runtime/UniTask.WhenAll.Generated.cs | 70 ----------- .../Runtime/UniTask.WhenAll.Generated.tt | 9 +- .../UniTask/Runtime/UniTask.WhenAll.cs | 10 -- .../Runtime/UniTask.WhenAny.Generated.cs | 70 ----------- .../Runtime/UniTask.WhenAny.Generated.tt | 9 +- .../UniTask/Runtime/UniTask.WhenAny.cs | 15 --- .../Runtime/UniTaskCompletionSource.cs | 71 ++++++----- .../UniTask/Runtime/UnityAsyncExtensions.cs | 80 ------------ .../UniTask/Runtime/UnityAsyncExtensions.tt | 16 --- src/UniTask/Assets/Scenes/SandboxMain.cs | 116 ++++++++++-------- .../ProjectSettings/ProjectSettings.asset | 2 +- 18 files changed, 106 insertions(+), 523 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs index c6315f5..18a9a68 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs @@ -143,14 +143,6 @@ namespace Cysharp.Threading.Tasks return pool.TryPush(this); } - ~WaitAsyncSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } - static void CancellationCallback(object state) { var self = (WaitAsyncSource)state; @@ -468,14 +460,6 @@ namespace Cysharp.Threading.Tasks return pool.TryPush(this); } - ~WaitAsyncSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } - static void CancellationCallback(object state) { var self = (WaitAsyncSource)state; diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs index d7d59dd..5e2af67 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs @@ -239,14 +239,6 @@ namespace Cysharp.Threading.Tasks.CompilerServices { core.OnCompleted(continuation, state, token); } - - ~AsyncUniTask() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } internal sealed class AsyncUniTask : IStateMachineRunnerPromise, IUniTaskSource, ITaskPoolNode> @@ -376,14 +368,6 @@ namespace Cysharp.Threading.Tasks.CompilerServices { core.OnCompleted(continuation, state, token); } - - ~AsyncUniTask() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs index 9a32026..91d3240 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs @@ -134,14 +134,6 @@ namespace Cysharp.Threading.Tasks return pool.TryPush(this); } - ~EnumeratorPromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } - // Unwrap YieldInstructions static IEnumerator ConsumeEnumerator(IEnumerator enumerator) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/AddressableAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/AddressableAsyncExtensions.cs index 4df373b..9b5fcb0 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/AddressableAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/AddressableAsyncExtensions.cs @@ -193,14 +193,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AsyncOperationHandleWithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class AsyncOperationHandleConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -314,14 +306,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AsyncOperationHandleConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion @@ -512,14 +496,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AsyncOperationHandleWithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class AsyncOperationHandleConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode> @@ -637,14 +613,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AsyncOperationHandleConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs index fc0def4..cecdac2 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs @@ -278,14 +278,6 @@ namespace Cysharp.Threading.Tasks originalUpdateAction = default; return pool.TryPush(this); } - - ~TweenConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs index a45bb32..4ebedf2 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs @@ -1,6 +1,7 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System; +using System.IO; using System.Runtime.CompilerServices; using System.Threading; using UnityEngine; @@ -181,14 +182,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~YieldPromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class NextFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -283,14 +276,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~NextFramePromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -406,14 +391,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~DelayFramePromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class DelayPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -524,14 +501,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~DelayPromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -642,14 +611,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~DelayIgnoreTimeScalePromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs index c427816..6228311 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs @@ -137,14 +137,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~WaitUntilPromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class WaitWhilePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -249,14 +241,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~WaitWhilePromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class WaitUntilCanceledPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -344,14 +328,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~WaitUntilCanceledPromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } // where T : UnityEngine.Object, can not add constraint @@ -475,14 +451,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~WaitUntilValueChangedUnityObjectPromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class WaitUntilValueChangedStandardObjectPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode> @@ -604,14 +572,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~WaitUntilValueChangedStandardObjectPromise() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs index e93a384..9ef07d6 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs @@ -131,11 +131,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3)> WhenAll(UniTask task1, UniTask task2, UniTask task3) @@ -295,11 +290,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4) @@ -495,11 +485,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) @@ -731,11 +716,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) @@ -1003,11 +983,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) @@ -1311,11 +1286,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) @@ -1655,11 +1625,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) @@ -2035,11 +2000,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) @@ -2451,11 +2411,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) @@ -2903,11 +2858,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) @@ -3391,11 +3341,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) @@ -3915,11 +3860,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) @@ -4475,11 +4415,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } public static UniTask<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)> WhenAll(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) @@ -5071,11 +5006,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } } } \ No newline at end of file diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.tt b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.tt index b837cbe..f14cb4c 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.tt +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.tt @@ -45,7 +45,7 @@ namespace Cysharp.Threading.Tasks public WhenAllPromise(<#= args #>) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; <# for(var j = 1; j <= i; j++) { #> @@ -92,7 +92,7 @@ namespace Cysharp.Threading.Tasks public (<#= t #>) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -116,11 +116,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } <# } #> } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.cs index 714da5b..39f6a9a 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAll.cs @@ -142,11 +142,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } sealed class WhenAllPromise : IUniTaskSource @@ -237,11 +232,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~WhenAllPromise() - { - core.Reset(); - } } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs index 72981b1..09b98e6 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs @@ -127,11 +127,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3)> WhenAny(UniTask task1, UniTask task2, UniTask task3) @@ -289,11 +284,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4) @@ -488,11 +478,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) @@ -724,11 +709,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) @@ -997,11 +977,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) @@ -1307,11 +1282,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) @@ -1654,11 +1624,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) @@ -2038,11 +2003,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) @@ -2459,11 +2419,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) @@ -2917,11 +2872,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) @@ -3412,11 +3362,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) @@ -3944,11 +3889,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) @@ -4513,11 +4453,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } public static UniTask<(int winArgumentIndex, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15)> WhenAny(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) @@ -5119,11 +5054,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.tt b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.tt index 2165c2c..b1b6a03 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.tt +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.tt @@ -37,7 +37,7 @@ namespace Cysharp.Threading.Tasks public WhenAnyPromise(<#= args #>) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; <# for(var j = 1; j <= i; j++) { #> @@ -86,7 +86,7 @@ namespace Cysharp.Threading.Tasks public (int, <#= tBool #>) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -110,11 +110,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } <# } #> diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.cs index 15ecd1f..09eb32d 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.cs @@ -171,11 +171,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyLRPromise() - { - core.Reset(); - } } @@ -268,11 +263,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } sealed class WhenAnyPromise : IUniTaskSource @@ -363,11 +353,6 @@ namespace Cysharp.Threading.Tasks { GetResult(token); } - - ~WhenAnyPromise() - { - core.Reset(); - } } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs index 638e50b..02d6ad7 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs @@ -38,13 +38,42 @@ namespace Cysharp.Threading.Tasks { } + internal class ExceptionHolder + { + ExceptionDispatchInfo exception; + bool calledGet = false; + + public ExceptionHolder(ExceptionDispatchInfo exception) + { + this.exception = exception; + } + + public ExceptionDispatchInfo GetException() + { + if (!calledGet) + { + calledGet = true; + GC.SuppressFinalize(this); + } + return exception; + } + + ~ExceptionHolder() + { + if (!calledGet) + { + UniTaskScheduler.PublishUnobservedTaskException(exception.SourceException); + } + } + } + [StructLayout(LayoutKind.Auto)] public struct UniTaskCompletionSourceCore { // Struct Size: TResult + (8 + 2 + 1 + 1 + 8 + 8) TResult result; - object error; // ExceptionDispatchInfo or OperationCanceledException + object error; // ExceptionHolder or OperationCanceledException short version; bool hasUnhandledError; int completedCount; // 0: completed == false @@ -78,9 +107,9 @@ namespace Cysharp.Threading.Tasks { UniTaskScheduler.PublishUnobservedTaskException(oc); } - else if (error is ExceptionDispatchInfo ei) + else if (error is ExceptionHolder e) { - UniTaskScheduler.PublishUnobservedTaskException(ei.SourceException); + UniTaskScheduler.PublishUnobservedTaskException(e.GetException().SourceException); } } catch @@ -129,7 +158,7 @@ namespace Cysharp.Threading.Tasks } else { - this.error = ExceptionDispatchInfo.Capture(error); + this.error = new ExceptionHolder(ExceptionDispatchInfo.Capture(error)); } if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) @@ -209,9 +238,9 @@ namespace Cysharp.Threading.Tasks { throw oce; } - else if (error is ExceptionDispatchInfo edi) + else if (error is ExceptionHolder eh) { - edi.Throw(); + eh.GetException().Throw(); } throw new InvalidOperationException("Critical: invalid exception type was held."); @@ -367,12 +396,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~UniTaskCompletionSource() - { - // clear error information. - core.Reset(); - } } public class AutoResetUniTaskCompletionSource : IUniTaskSource, ITaskPoolNode, IPromise @@ -495,15 +518,6 @@ namespace Cysharp.Threading.Tasks core.Reset(); return pool.TryPush(this); } - - ~AutoResetUniTaskCompletionSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - return; - } - } } public class UniTaskCompletionSource : IUniTaskSource, IPromise @@ -593,12 +607,6 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - ~UniTaskCompletionSource() - { - // clear error information. - core.Reset(); - } } public class AutoResetUniTaskCompletionSource : IUniTaskSource, ITaskPoolNode>, IPromise @@ -726,15 +734,6 @@ namespace Cysharp.Threading.Tasks core.Reset(); return pool.TryPush(this); } - - - ~AutoResetUniTaskCompletionSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs index 1817d11..27b6acd 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs @@ -185,14 +185,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AsyncOperationWithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class AsyncOperationConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -299,14 +291,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AsyncOperationConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion @@ -491,14 +475,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~ResourceRequestWithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class ResourceRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -609,14 +585,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~ResourceRequestConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion @@ -801,14 +769,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AssetBundleRequestWithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class AssetBundleRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -919,14 +879,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AssetBundleRequestConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion @@ -1111,14 +1063,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AssetBundleCreateRequestWithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class AssetBundleCreateRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -1229,14 +1173,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~AssetBundleCreateRequestConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion @@ -1439,14 +1375,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~UnityWebRequestAsyncOperationWithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class UnityWebRequestAsyncOperationConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -1565,14 +1493,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~UnityWebRequestAsyncOperationConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt index 61279a3..31e78dd 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt @@ -258,14 +258,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~<#= t.typeName #>WithCancellationSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } sealed class <#= t.typeName #>ConfiguredSource : <#= ToIUniTaskSourceReturnType(t.returnType) #>, IPlayerLoopItem, ITaskPoolNode<<#= t.typeName #>ConfiguredSource> @@ -396,14 +388,6 @@ namespace Cysharp.Threading.Tasks cancellationToken = default; return pool.TryPush(this); } - - ~<#= t.typeName #>ConfiguredSource() - { - if (TryReturn()) - { - GC.ReRegisterForFinalize(this); - } - } } #endregion diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 9dacea2..19622bc 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -184,6 +184,7 @@ public class SandboxMain : MonoBehaviour } + async UniTask RunStandardDelayAsync() { UnityEngine.Debug.Log("DEB"); @@ -422,10 +423,23 @@ public class SandboxMain : MonoBehaviour Debug.Log($"{v.isDone} {v.isHttpError} {v.isNetworkError}"); Debug.Log(v.downloadHandler.text); } + private async void Go() + { + await UniTask.DelayFrame(0); + } + + async UniTask Foo() + { + await UniTask.DelayFrame(10); + throw new Exception("yeah"); + } void Start() { + _ = Foo(); // unhandled. + Go(); + UnityEngine.Debug.Log("Start:" + PlayerLoopInfo.CurrentLoopType); //PlayerLoopInfo.Inject(); @@ -441,76 +455,76 @@ public class SandboxMain : MonoBehaviour // rp.AddTo(this.GetCancellationTokenOnDestroy()); - var cts = new CancellationTokenSource(); + //var cts = new CancellationTokenSource(); - okButton.onClick.AddListener(UniTask.UnityAction(async () => - { - _ = ExecuteAsync(); + //okButton.onClick.AddListener(UniTask.UnityAction(async () => + //{ + // _ = ExecuteAsync(); - await UniTask.Yield(); + // await UniTask.Yield(); - //await DelayCheck(); - /* - UnityEngine.Debug.Log("click:" + PlayerLoopInfo.CurrentLoopType); - StartCoroutine(CoroutineRun()); - StartCoroutine(CoroutineRun2()); - _ = AsyncRun(); - _ = AsyncLastUpdate(); - _ = AsyncLastLast(); - */ - //await UniTask.Yield(); - //_ = Test2(); - // EarlyUpdate.ExecuteMainThreadJobs - // _ = Test2(); + // //await DelayCheck(); + // /* + // UnityEngine.Debug.Log("click:" + PlayerLoopInfo.CurrentLoopType); + // StartCoroutine(CoroutineRun()); + // StartCoroutine(CoroutineRun2()); + // _ = AsyncRun(); + // _ = AsyncLastUpdate(); + // _ = AsyncLastLast(); + // */ + // //await UniTask.Yield(); + // //_ = Test2(); + // // EarlyUpdate.ExecuteMainThreadJobs + // // _ = Test2(); - //var t = await Resources.LoadAsync(Application.streamingAssetsPath + "test.txt"); - //Debug.Log("LoadEnd" + PlayerLoopInfo.CurrentLoopType + ", " + (t != null)); - //Debug.Log("LoadEnd" + PlayerLoopInfo.CurrentLoopType + ", " + ((TextAsset)t).text); + // //var t = await Resources.LoadAsync(Application.streamingAssetsPath + "test.txt"); + // //Debug.Log("LoadEnd" + PlayerLoopInfo.CurrentLoopType + ", " + (t != null)); + // //Debug.Log("LoadEnd" + PlayerLoopInfo.CurrentLoopType + ", " + ((TextAsset)t).text); - //await UniTask.Yield(PlayerLoopTiming.LastUpdate); - //UnityEngine.Debug.Log("after update:" + Time.frameCount); - ////await UniTask.NextFrame(); - ////await UniTask.Yield(); - ////UnityEngine.Debug.Log("after update nextframe:" + Time.frameCount); + // //await UniTask.Yield(PlayerLoopTiming.LastUpdate); + // //UnityEngine.Debug.Log("after update:" + Time.frameCount); + // ////await UniTask.NextFrame(); + // ////await UniTask.Yield(); + // ////UnityEngine.Debug.Log("after update nextframe:" + Time.frameCount); - //StartCoroutine(CoroutineRun2()); - ////StartCoroutine(CoroutineRun()); - //UnityEngine.Debug.Log("FOO?"); + // //StartCoroutine(CoroutineRun2()); + // ////StartCoroutine(CoroutineRun()); + // //UnityEngine.Debug.Log("FOO?"); - //_ = DelayFrame3_Pre(); - //await UniTask.Yield(); + // //_ = DelayFrame3_Pre(); + // //await UniTask.Yield(); - })); + //})); - cancelButton.onClick.AddListener(UniTask.UnityAction(async () => - { - _ = DelayFrame3_Post(); - await UniTask.Yield(); + //cancelButton.onClick.AddListener(UniTask.UnityAction(async () => + //{ + // _ = DelayFrame3_Post(); + // await UniTask.Yield(); - //await UniTask.Yield(PlayerLoopTiming.LastPreUpdate); - //UnityEngine.Debug.Log("before update:" + Time.frameCount); - //await UniTask.NextFrame(); - //await UniTask.Yield(); - //UnityEngine.Debug.Log("before update nextframe:" + Time.frameCount); + // //await UniTask.Yield(PlayerLoopTiming.LastPreUpdate); + // //UnityEngine.Debug.Log("before update:" + Time.frameCount); + // //await UniTask.NextFrame(); + // //await UniTask.Yield(); + // //UnityEngine.Debug.Log("before update nextframe:" + Time.frameCount); - //StartCoroutine(CoroutineRun()); + // //StartCoroutine(CoroutineRun()); - //UnityEngine.Debug.Log("click:" + PlayerLoopInfo.CurrentLoopType); - //_ = Yieldding(); + // //UnityEngine.Debug.Log("click:" + PlayerLoopInfo.CurrentLoopType); + // //_ = Yieldding(); - //var cts = new CancellationTokenSource(); + // //var cts = new CancellationTokenSource(); - //UnityEngine.Debug.Log("click:" + PlayerLoopInfo.CurrentLoopType + ":" + Time.frameCount); - //var la = SceneManager.LoadSceneAsync("Scenes/ExceptionExamples").WithCancellation(cts.Token); - ////cts.Cancel(); - //await la; - //UnityEngine.Debug.Log("End LoadSceneAsync" + PlayerLoopInfo.CurrentLoopType + ":" + Time.frameCount); - })); + // //UnityEngine.Debug.Log("click:" + PlayerLoopInfo.CurrentLoopType + ":" + Time.frameCount); + // //var la = SceneManager.LoadSceneAsync("Scenes/ExceptionExamples").WithCancellation(cts.Token); + // ////cts.Cancel(); + // //await la; + // //UnityEngine.Debug.Log("End LoadSceneAsync" + PlayerLoopInfo.CurrentLoopType + ":" + Time.frameCount); + //})); //return; //await UniTask.SwitchToMainThread(); diff --git a/src/UniTask/ProjectSettings/ProjectSettings.asset b/src/UniTask/ProjectSettings/ProjectSettings.asset index e49b1d3..3fd3e00 100644 --- a/src/UniTask/ProjectSettings/ProjectSettings.asset +++ b/src/UniTask/ProjectSettings/ProjectSettings.asset @@ -557,7 +557,7 @@ PlayerSettings: platformArchitecture: {} scriptingBackend: Android: 1 - Standalone: 1 + Standalone: 0 il2cppCompilerConfiguration: {} managedStrippingLevel: {} incrementalIl2cppBuild: {}