Search Issue Tracker
By Design
By Design in 6000.7.X
Votes
0
Found in
6000.0.78f1
6000.3.19f1
6000.5.2f1
6000.6.0b2
6000.7.0a1
Issue ID
UUM-145821
Regression
No
NullReferenceException is outputted when using Awaitable.Cancel
Steps to reproduce:
1. Open the attached user's project "awaitable-cancel-repro.zip"
2. Open the "Assets/Scenes/SampleScene.unity" and enter play mode
3. Observe the console window:
The AwaitableCancel MonoBehaviour on the "AwaitableTest - Cancel with Cancel() => NullReferenceException" GameObject produces a NullReferenceException
The AwaitableCancel MonoBehaviour on the "AwaitableTest - Cancel with token => works" GameObject doesn't produce an error
Actual result: error from using `Awaitable.Cancel`, but not if cancellation is done with a CancellationTokenSource instead
Expected result: no error from using `Awaitable.Cancel` to cancel an Awaitable
Reproducible with: 6000.0.78f1, 6000.3.19f1, 6000.5.2f1, 6000.6.0b2, 6000.7.0a1
Testing Environment: Windows 11
Not reproducible on: no other environment tested
Notes:
-The documentation https://docs.unity3d.com/ScriptReference/Awaitable.Cancel.html states:
Cancels the awaitable. If the awaitable is being awaited, the awaiter receives a System.OperationCanceledException
Note: some methods returning an Awaitable also accept a CancellationToken. Both cancelation models are equivalent
-Both cancelation models are not equivalient in this scenario
-error:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Awaitable`1[T].SetResultAndRaiseContinuation (T result) (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
UnityEngine.AwaitableCompletionSource`1[T].TrySetResult (T& value) (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
AwaitableCancel.Update () (at Assets/AwaitableCancel.cs:46)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <932fbe8ac5a946808aa5d7b95844e18c>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on CheckDeviceStatus when converting materials from built-in to URP and using DX12
- Higher CPU frame time on Android devices with Cortex-A510 efficiency cores (vs Cortex-A55)
- Alt+click on List header does not recursively toggle child foldouts when items use a UI Toolkit CustomPropertyDrawer
- Hub Window is closed when closing Unity AI Window via the OS Window Close Button on Windows
- Artifacts are rendered in UITK when using Font Assets and using negative outlines
Resolution Note:
The NullReferenceException doesn't happen because of Awaitable.Cancel, it happens because you are setting the value after having awaited the Awaitable.
As Awaitables are returned to the pool, it's not safe to used them after you have awaited them.
Resolution Note (6000.7.X):
The NullReferenceException doesn't happen because of Awaitable.Cancel, it happens because you are setting the value after having awaited the Awaitable.
As Awaitables are returned to the pool, it's not safe to used them after you have awaited them.