Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert hit in UnityAsyncUtil package #22

Open
JPerryOddGames opened this issue Mar 30, 2022 · 4 comments
Open

Assert hit in UnityAsyncUtil package #22

JPerryOddGames opened this issue Mar 30, 2022 · 4 comments

Comments

@JPerryOddGames
Copy link

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)

@AndrzejLorek
Copy link

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
	...
}

@JPerryOddGames
Copy link
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

@StephenHodgson
Copy link

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.

@dethroneofall
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants