相关文章推荐

Upvote https://issuetracker.unity3d.com/is…pting-back-end-when-async-slash-await-is-used

I’m sending all exceptions to online analytics to quickly fix bugs but sometimes il2cpp stack traces are useless and it’s impossible to see what caused an issue or where it happened:

public class TestButton: MonoBehaviour
    [SerializeField] Button button;
    private void Start()
        button.onClick.AddListener( async () => await TestTask() );
        //or button.onClick.AddListener( () => TestTask() );
    private async Task TestTask()
        await Task.Yield();
        throw new System.NullReferenceException();
    //private async void Start()
    //    await Task.Yield();
    //    throw new System.NullReferenceException();

Mono:

NullReferenceException: Object reference not set to an instance of an object.
  at TestButton+<TestTask>d__8.MoveNext () [0x0006e] in <d18fdfa825c14b36ae03c1897d413257>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at TestButton+<<Start>b__6_0>d.MoveNext () [0x00062] in <d18fdfa825c14b36ae03c1897d413257>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in <12d10dc81c174d13b71f46cfb761f21d>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext:Exec()
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

Il2cpp:

NullReferenceException: Object reference not set to an instance of an object.
  at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
  at System.Reflection.TargetParameterCountException..ctor (System.String message) [0x00000] in <00000000000000000000000000000000>:0
  at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task task, System.Boolean canInlineContinuationTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.AsyncLocal`1[T].set_Value (T value) [0x00000] in <00000000000000000000000000000000>:0
  at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WaitForSecondsRealtime:set_waitTime(Single)
UnityEngine.UnitySynchronizationContext:Exec()

It also doesn’t work correctly in Debug il2cpp mode.

Kamyker:

I’m sending all exceptions to online analytics to quickly fix bugs but sometimes il2cpp stack traces are useless and it’s impossible to see what caused an issue or where it happened:

public class TestButton: MonoBehaviour
    [SerializeField] Button button;
    private void Start()
        button.onClick.AddListener( async () => await TestTask() );
        //or button.onClick.AddListener( () => TestTask() );
    private async Task TestTask()
        await Task.Yield();
        throw new System.NullReferenceException();
    //private async void Start()
    //    await Task.Yield();
    //    throw new System.NullReferenceException();

Mono:

NullReferenceException: Object reference not set to an instance of an object.
  at TestButton+<TestTask>d__8.MoveNext () [0x0006e] in <d18fdfa825c14b36ae03c1897d413257>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at TestButton+<<Start>b__6_0>d.MoveNext () [0x00062] in <d18fdfa825c14b36ae03c1897d413257>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <4756199cf52a4f14b33cdcc5659f782e>:0
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in <12d10dc81c174d13b71f46cfb761f21d>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext:Exec()
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

Il2cpp:

NullReferenceException: Object reference not set to an instance of an object.
  at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
  at System.Reflection.TargetParameterCountException..ctor (System.String message) [0x00000] in <00000000000000000000000000000000>:0
  at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task task, System.Boolean canInlineContinuationTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.AsyncLocal`1[T].set_Value (T value) [0x00000] in <00000000000000000000000000000000>:0
  at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WaitForSecondsRealtime:set_waitTime(Single)
UnityEngine.UnitySynchronizationContext:Exec()

It also doesn’t work correctly in Debug il2cpp mode.

Can you submit a bug report for this issue? It looks like something that we should correct.

[quote=“JoshPeterson, post:2, topic: 815345, username:JoshPeterson”]
Can you submit a bug report for this issue? It looks like something that we should correct.
[/quote]1289863

That project is a bit messy but it seems like that’s the reasons of missing stack trace.

In clean project I get:

NullReferenceException: Object reference not set to an instance of an object.
  at TestButton.<Start>b__2_0 () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
  at System.Reflection.TargetParameterCountException..ctor (System.String message) [0x00000] in <00000000000000000000000000000000>:0
  at TestButton.<Start>b__2_0 () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task task, System.Boolean canInlineContinuationTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Create () [0x00000] in <00000000000000000000000000000000>:0
  at TestButton.<Start>b__2_0 () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WaitForSecondsRealtime:set_waitTime(Single)
UnityEngine.UnitySynchronizationContext:Exec()

A bit better, now I have TestButton. but still not as good as mono (TestButton+). Anyway once a bit more code is added to the project then that line is somehow replaced with something completely random:

NullReferenceException: Object reference not set to an instance of an object.
  at TestInput.get_XRScheme () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.LowLevel.PlayerLoopSystem+UpdateFunction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0

Project that gives that error: https://drive.google.com/file/d/1L_4s7bbTEL0dBNQQ9_UaZXctKfoGtfMI/view?usp=sharing

In my main project I get these kind of weird stack traces with tons of unrelated calls, for ex:

IndexOutOfRangeException: Index was outside the bounds of the array.: MusicPlayer+<RaiseVolume>d__21.System.Collections.IEnumerator.Reset () (at <00000000000000000000000000000000>:0)
BA.Game.UI.ResultController.SetResults (System.Int32 mapScore, System.Int32 maxCombo, System.Int32 totalScore, System.Single accuracy) (at <00000000000000000000000000000000>:0)
TextCtrl+<DDAnim>d__5.System.Collections.IEnumerator.Reset () (at <00000000000000000000000000000000>:0)
BA.Game.GameFlow.GameEnded (System.Boolean won) (at)

These are 3 lines out of 30+ reported, MusicPlayer+:

IEnumerator RaiseVolume()
    while ( AudioListener.volume < volume )
        AudioListener.volume += Time.deltaTime * 0.1f;
        yield return null;

This bug couldn’t even happen here :frowning:

1289863

That project is a bit messy but it seems like that’s the reasons of missing stack trace.

In clean project I get:

NullReferenceException: Object reference not set to an instance of an object.
  at TestButton.<Start>b__2_0 () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
  at System.Reflection.TargetParameterCountException..ctor (System.String message) [0x00000] in <00000000000000000000000000000000>:0
  at TestButton.<Start>b__2_0 () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task task, System.Boolean canInlineContinuationTask) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Create () [0x00000] in <00000000000000000000000000000000>:0
  at TestButton.<Start>b__2_0 () [0x00000] in <00000000000000000000000000000000>:0
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WaitForSecondsRealtime:set_waitTime(Single)
UnityEngine.UnitySynchronizationContext:Exec()

A bit better, now I have TestButton. but still not as good as mono (TestButton+). Anyway once a bit more code is added to the project then that line is somehow replaced with something completely random:

NullReferenceException: Object reference not set to an instance of an object.
  at TestInput.get_XRScheme () [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.LowLevel.PlayerLoopSystem+UpdateFunction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
  at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0

Project that gives that error: https://drive.google.com/file/d/1L_4s7bbTEL0dBNQQ9_UaZXctKfoGtfMI/view?usp=sharing

In my main project I get these kind of weird stack traces with tons of unrelated calls, for ex:

IndexOutOfRangeException: Index was outside the bounds of the array.: MusicPlayer+<RaiseVolume>d__21.System.Collections.IEnumerator.Reset () (at <00000000000000000000000000000000>:0)
BA.Game.UI.ResultController.SetResults (System.Int32 mapScore, System.Int32 maxCombo, System.Int32 totalScore, System.Single accuracy) (at <00000000000000000000000000000000>:0)
TextCtrl+<DDAnim>d__5.System.Collections.IEnumerator.Reset () (at <00000000000000000000000000000000>:0)
BA.Game.GameFlow.GameEnded (System.Boolean won) (at)

These are 3 lines out of 30+ reported, MusicPlayer+:

IEnumerator RaiseVolume()
    while ( AudioListener.volume < volume )
        AudioListener.volume += Time.deltaTime * 0.1f;
        yield return null;

This bug couldn’t even happen here :frowning:

Thanks for the bug report. It is certainly possible that stack traces with IL2CPP may be missing frames due to inlining. But there should not be any incorrect frames. We will investigate this.

JoshPeterson:

It is certainly possible that stack traces with IL2CPP may be missing frames due to inlining.

But this should not be the case in debug builds, right?

Il2cpp - wrong
Il2cpp Debug C++ compiler configuration - wrong
Il2cpp Development - fine (Release or Debug C++ compiler configuration)

Tried attaching [MethodImpl( MethodImplOptions.NoInlining )] to code above and also to all methods and properties in all managed dlls using Cecil, il2cpp generated noinline but it didn’t help. No idea, myb c++ async runner gets inlined?

Il2cpp development build doesn’t fix my problem, can’t distribute that to players.

Would it be somehow possible to force il2cpp development build behavior in normal il2cpp for specific methods or whole async/await logic?

I’d like to know if this issue is possible to fix or not so I can start going back to mono or change as much as possible async/await to coroutines.

JoshPeterson:

I’m unsure why our QA team did not process this bug report yet. I’ve pinged them about it.

still nothing

[quote=“JoshPeterson, post:10, topic: 815345, username:JoshPeterson”]
It looks like our QA team started to process it, but then ran into an unrelated issue, and may have moved it to the back burner. I’ll ping them again. Thanks for following up here.
[/quote]Thanks, looks like it got reproduced https://issuetracker.unity3d.com/issues/il2cpp-stack-trace-does-not-match-mono-scripting-back-end-when-async-slash-await-is-used

I’ve finally had a chance to look into this issue. Thanks again for reporting it, these stack trace problems can be very specific to the code layout in a given project, and therefore difficult to reproduce.

It turns out the problem is not specific to async/await workflows. More generally, IL2CPP is reporting incorrect stack frame entries for any instance methods on value types. Due to an implementation detail about how IL2CPP implements these methods, they were not being found properly by the stack trace creation code.

I’ve been able to correct this issue, and it should be going out to patch releases in all active versions of Unity.

@Kamyker : I’ll ping you via the submitted bug report when the fix clears our testing and code review processes.

Want to add +1 too. Even without using async / await stuff all IL2CPP stack addresses are pretty useless. There is nothing to do with them.
I found another thread with such similar issue: IL2CPP missing line numbers in stack trace
It’s really sad to see that nothing has moved since last year. It’s really poor.

CheeryLee:

Want to add +1 too. Even without using async / await stuff all IL2CPP stack addresses are pretty useless. There is nothing to do with them.
I found another thread with such similar issue: https://discussions.unity.com/t/772256
It’s really sad to see that nothing has moved since last year. It’s really poor.

Regarding line numbers in stack traces, it is on out list of things we would like to do, but we’ve not had the resources to complete it yet. I’m hoping that will change soon, but I cannot promise anything.

[quote=“CheeryLee, post:15, topic: 815345, username:CheeryLee”]
Even without using async / await stuff all IL2CPP stack addresses are pretty useless. There is nothing to do with them.
[/quote]I disagree you can always split a method to smaller parts to pinpoint an issue.

The wait for 2020.2.5 begins.

@JoshPeterson Thank you!

 
推荐文章