Cysharp/UniTask

Disposing UnityWebRequest gets thrown error

hagabooga opened this issue · 3 comments

I get this thrown error and I know it's because I dispose the UnityWebRequest manually. Should there be a check around (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/UnityAsyncExtensions.cs:903) or should I deal with this outside of the UniTask library?

ArgumentNullException: Value cannot be null. Parameter name: _unity_self Cysharp.Threading.Tasks.Internal.UnityWebRequestResultExtensions.IsError (UnityEngine.Networking.UnityWebRequest unityWebRequest) (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/Internal/UnityWebRequestExtensions.cs:17) Cysharp.Threading.Tasks.UnityAsyncExtensions+UnityWebRequestAsyncOperationConfiguredSource.MoveNext () (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/UnityAsyncExtensions.cs:903) Cysharp.Threading.Tasks.Internal.PlayerLoopRunner.RunCore () (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/Internal/PlayerLoopRunner.cs:175) UnityEngine.Debug:LogException(Exception) Cysharp.Threading.Tasks.Internal.<>c:<.ctor>b__9_0(Exception) (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/Internal/PlayerLoopRunner.cs:25) Cysharp.Threading.Tasks.Internal.PlayerLoopRunner:RunCore() (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/Internal/PlayerLoopRunner.cs:189) Cysharp.Threading.Tasks.Internal.PlayerLoopRunner:Update() (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/Internal/PlayerLoopRunner.cs:145) Cysharp.Threading.Tasks.Internal.PlayerLoopRunner:Run() (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/Internal/PlayerLoopRunner.cs:104)

It seems that if I dispose of the request, AsyncOperation.webRequest will be null.

        var req = UnityWebRequest.Get("https://google.com");
        var operation = req.SendWebRequest();
        req.Dispose();
        await operation;

Hello, Perhaps you are disposing of the UnityWebRequest in the process..?
If so, it seems like an illigal operation. Please confirm.

I fixed it in #494, so that you get the proper error message instead of a null error.

I checked it and I get a proper error message instead of a null error now. Thanks!