Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug [1289863] Il2cpp useless stack traces (for async/await)

Discussion in 'Windows' started by Kamyker, Nov 22, 2020.

  1. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,084
    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:
    Code (CSharp):
    1. public class TestButton: MonoBehaviour
    2. {
    3.     [SerializeField] Button button;
    4.  
    5.     private void Start()
    6.     {
    7.         button.onClick.AddListener( async () => await TestTask() );
    8.         //or button.onClick.AddListener( () => TestTask() );
    9.     }
    10.  
    11.     private async Task TestTask()
    12.     {
    13.         await Task.Yield();
    14.         throw new System.NullReferenceException();
    15.     }
    16.  
    17.     //or
    18.     //private async void Start()
    19.     //{
    20.     //    await Task.Yield();
    21.     //    throw new System.NullReferenceException();
    22.     //}
    23. }

    Mono:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object.
    2.   at TestButton+<TestTask>d__8.MoveNext () [0x0006e] in <d18fdfa825c14b36ae03c1897d413257>:0
    3. --- End of stack trace from previous location where exception was thrown ---
    4.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4756199cf52a4f14b33cdcc5659f782e>:0
    5.   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <4756199cf52a4f14b33cdcc5659f782e>:0
    6.   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <4756199cf52a4f14b33cdcc5659f782e>:0
    7.   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <4756199cf52a4f14b33cdcc5659f782e>:0
    8.   at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <4756199cf52a4f14b33cdcc5659f782e>:0
    9.   at TestButton+<<Start>b__6_0>d.MoveNext () [0x00062] in <d18fdfa825c14b36ae03c1897d413257>:0
    10. --- End of stack trace from previous location where exception was thrown ---
    11.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4756199cf52a4f14b33cdcc5659f782e>:0
    12.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <4756199cf52a4f14b33cdcc5659f782e>:0
    13.   at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in <12d10dc81c174d13b71f46cfb761f21d>:0
    14. UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    15. UnityEngine.DebugLogHandler:LogException(Exception, Object)
    16. UnityEngine.Logger:LogException(Exception, Object)
    17. UnityEngine.Debug:LogException(Exception)
    18. UnityEngine.WorkRequest:Invoke()
    19. UnityEngine.UnitySynchronizationContext:Exec()
    20. UnityEngine.UnitySynchronizationContext:ExecuteTasks()
    Il2cpp:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object.
    2.   at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
    3.   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    4.   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    5.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    6.   at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    7.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    8.   at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
    9.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    10. --- End of stack trace from previous location where exception was thrown ---
    11.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    12.   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
    13.   at System.Reflection.TargetParameterCountException..ctor (System.String message) [0x00000] in <00000000000000000000000000000000>:0
    14.   at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
    15.   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    16.   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    17.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    18.   at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    19.   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    20.   at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0
    21.   at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task task, System.Boolean canInlineContinuationTask) [0x00000] in <00000000000000000000000000000000>:0
    22.   at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0
    23.   at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0
    24.   at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0
    25.   at System.Threading.AsyncLocal`1[T].set_Value (T value) [0x00000] in <00000000000000000000000000000000>:0
    26.   at Test.remove_EventSingle (Delegate value) [0x00000] in <00000000000000000000000000000000>:0
    27.   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    28.   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    29.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    30.   at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    31.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    32.   at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
    33.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    34. --- End of stack trace from previous location where exception was thrown ---
    35.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    36.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    37.   at UnityEngine.WaitForSecondsRealtime.set_waitTime (System.Single value) [0x00000] in <00000000000000000000000000000000>:0
    38.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    39. UnityEngine.Logger:LogException(Exception, Object)
    40. UnityEngine.Debug:LogException(Exception)
    41. UnityEngine.WaitForSecondsRealtime:set_waitTime(Single)
    42. UnityEngine.UnitySynchronizationContext:Exec()
    It also doesn't work correctly in Debug il2cpp mode.