Skip to content

Assert hit in UnityAsyncUtil package #22

Description

@JPerryOddGames

We're experiencing the Assert failing in the SimpleCoroutineAwaiter implementation of INotifyCompletion.OnCompleted.

We've also seen this error pop up many times before in random places. This particular part of the code is just waiting on a WaitForUpdate instance.
Unfortunately I don't have any other details, and I've not been able to reproduce this despite many attempts. As far as I can tell the generated task state machine code should only invoke the OnCompleted method once ever, so I really don't understand how this could happen.

The Stacktrace

System.Exception Assert hit in UnityAsyncUtil package!
0 IEnumeratorAwaitExtensions.Assert (System.Boolean condition) (<00000000000000000000000000000000>:0)
1 IEnumeratorAwaitExtensions+SimpleCoroutineAwaiter.System.Runtime.CompilerServices.INotifyCompletion.OnCompleted (System.Action continuation) (<00000000000000000000000000000000>:0)
2 System.Runtime.CompilerServices.AsyncVoidMethodBuilder.AwaitOnCompleted[TAwaiter,TStateMachine] (TAwaiter& awaiter, TStateMachine& stateMachine) (<00000000000000000000000000000000>:0)
3 ODDFramework.AdProviderBase+d__40.MoveNext () (<00000000000000000000000000000000>:0)

Activity

  1. AndrzejLorek commented on Apr 5, 2022

    @AndrzejLorek

    Hi, I have the same exceptions on production. Android and iOS. Different system version numbers and different devices. No common features. I was unable to reproduce this during testing on my devices.

    An example of an exception from Android. After receiving a callback from an admob native plugin, that is not invoked on the main thread, I want to wait for the main thread to change the icon state on unity UI.

    Exception:

    Exception : Assert hit in UnityAsyncUtil package!
           at IEnumeratorAwaitExtensions.Assert(IEnumeratorAwaitExtensions)
           at IEnumeratorAwaitExtensions+SimpleCoroutineAwaiter.System.Runtime.CompilerServices.INotifyCompletion.OnCompleted(IEnumeratorAwaitExtensions+SimpleCoroutineAwaiter.System.Runtime.CompilerServices.INotifyCompletion)
           at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].AwaitOnCompleted[TAwaiter,TStateMachine](System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult])
           at AdMobAdNetwork+<RewardedAdLoadedTask>d__16.MoveNext(AdMobAdNetwork+<RewardedAdLoadedTask>d__16)
           at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](System.Runtime.CompilerServices.AsyncTaskMethodBuilder)
           at AdMobAdNetwork.RewardedAdLoadedTask(AdMobAdNetwork)
           at AdMobAdNetwork+<HandleRewardedAdLoaded>d__15.MoveNext(AdMobAdNetwork+<HandleRewardedAdLoaded>d__15)
           at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](System.Runtime.CompilerServices.AsyncVoidMethodBuilder)
           at AdMobAdNetwork.HandleRewardedAdLoaded(AdMobAdNetwork)
           at System.EventHandler`1[TEventArgs].Invoke(System.EventHandler`1[TEventArgs])
           at System.EventHandler`1[TEventArgs].Invoke(System.EventHandler`1[TEventArgs])
           at System.Reflection.MonoMethod.Invoke(System.Reflection.MonoMethod)
           at System.Reflection.MethodBase.Invoke(System.Reflection.MethodBase)
           at UnityEngine.AndroidJavaProxy.Invoke(UnityEngine.AndroidJavaProxy)
           at UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod(UnityEngine._AndroidJNIHelper)
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Runtime.ExceptionServices.ExceptionDispatchInfo)
           at System.Threading.WaitCallback.Invoke(System.Threading.WaitCallback)
           at System.Threading.ContextCallback.Invoke(System.Threading.ContextCallback)
           at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext)
           at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext)
           at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem(System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem)
           at System.Threading.ThreadPoolWorkQueue.Dispatch(System.Threading.ThreadPoolWorkQueue)
    

    Code:

    private static async void HandleRewardedAdLoaded(object sender, EventArgs e) //callback invoked from admob plugin
    {
    	await RewardedAdLoadedTask();
    }
    
    private static async Task RewardedAdLoadedTask()
    {
    	await new WaitForUpdate();
    
    	//some action to do on main thread
    	...
    }
    
  2. JPerryOddGames commented on Apr 6, 2022

    @JPerryOddGames
    Author

    Just posting to add some additional info:
    I can fairly confidently confirm that this only happens when awaiting a WaitForUpdate from a task that isn't running on the main Unity thread. I can also see this primarily occurs after receiving an AdMob callback on a non-main thread, just as AndrzejLorek mentioned in the post above

  3. StephenHodgson commented on Apr 6, 2022

    @StephenHodgson

    funny because I usually use WaitForUpdate to get back to the main thread. But I've forked this and heavily modified it from this source code. Not sure what the difference could be.

  4. dethroneofall commented on Jun 8, 2023

    @dethroneofall

    We're experiencing the Assert failing in the SimpleCoroutineAwaiter implementation of INotifyCompletion.OnCompleted.

    We've also seen this error pop up many times before in random places. This particular part of the code is just waiting on a WaitForUpdate instance. Unfortunately I don't have any other details, and I've not been able to reproduce this despite many attempts. As far as I can tell the generated task state machine code should only invoke the OnCompleted method once ever, so I really don't understand how this could happen.

    The Stacktrace

    hi, did you manage to solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions