Страницы

вторник, 10 января 2017 г.

Unity's Assert loses stack frames in release: tests

All below done with BuildOptions.ForceEnableAssertions, messages logged with NSLog or Console.WriteLine to be in release build (not just debug) Unity 5.5.0f3 on iPhone


Suppose client code:
Assert.IsFalse(true); // Unity's assert, not System
in our case it leads internally to the following call: Debug.LogAssertion(message)

1. That stack we receive in Application.logMessageReceived callback:


UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)

2. That message we see in Xcode console (it is made by Unity automatically)


Assertion failed. Value was True
Expected: False
UnityEngine.Events.InvokableCallList:Invoke(Object[])
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)

3. And that stack we get through new StackTrace(0, true) at the point of the call:


MyPanelBehaviour:OnClickA()
UnityEngine.Events.InvokableCallList:Invoke(Object[] parameters)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject target, BaseEventData eventData, EventFunction`1 functor)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData pointerEvent, Boolean pressed, Boolean released)

You see, that new StackTrace(0, true) at the point of the call is most useful because only it contains OnClickA()*

So, to collect managed stack traces successfully we need to collect stack manually with new StackTrace.

Note: string StackTraceUtility.ExtractStackTrace() may be useful too. It uses new StackTrace(...) inside but additionally formats it to readable string in Unity stack style

* Note that, on earlier version of Unity I got OnClickA() in 2 too
on earlier version of Unity I got OnClickA() in 2 too

Комментариев нет:

Отправить комментарий