getsentry / sentry-unity

Development of Sentry SDK for Unity
https://docs.sentry.io/platforms/unity/
MIT License
210 stars 52 forks source link

Sentry Unity IL2CPP/Android doesn't trap exceptions #1276

Closed perholmes closed 5 months ago

perholmes commented 1 year ago

Environment

Unity 2023.1.0a25 Sentry Unity 1.2.0 Android 13 Phone

Problem

We get C++ IL2CPP stack traces on exceptions, and proper C# stack traces on capture message.

CaptureMessage works

On SentrySdk.CaptureMessage calls, normal stack traces are received:

image

The stack traces aren't perfect. There are some frames missing that are showing if we just log the exception through a log listener. But it's something.

image

Exceptions return C++ IL2CPP stack traces

On throw an exception or any natural exception like a C# null pointer, you get a C++ IL2CPP stack trace:

image

image

image

But logging exceptions works

A simple logging exception handler works, so there clearly isn't a general problem with getting stack traces through IL2CPP:

image


04-07 14:10:18.372 12301 12345 I Unity   : Log.Assert (System.Boolean condition, System.String message) (at D:/Dev/Unity/Green Screener 2/Assets/Unity Common/Logging/Log.cs:162)
04-07 14:10:18.372 12301 12345 I Unity   : Main.HardAssert (MenuItemBase menuItem) (at D:/Dev/Unity/Green Screener 2/Assets/App/Main/MainDialogs.cs:264)
04-07 14:10:18.372 12301 12345 I Unity   : Main.SanitizeImageSourceName (System.String input) (at D:/Dev/Unity/Green Screener 2/Assets/App/Main/MainDialogs.cs:100)
04-07 14:10:18.372 12301 12345 I Unity   : Cysharp.Threading.Tasks.UniTask+ExceptionResultSource`1[T].Finalize () (at ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/UniTask.Factory.cs:290)
04-07 14:10:18.372 12301 12345 I Unity   : UnityEngine.UIElements.EventCallbackRegistry+DynamicCallbackList.Invoke (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target) (at <00000000000000000000000000000000>:0)
04-07 14:10:18.372 12301 12345 I Unity   : UnityEngine.UIElements.NavigateFocusRing+FocusableHierarchyTraversal.StrictOrder (UnityEngine.UIElements.VisualElement a, UnityEngine.UIElements.VisualElement b) (at <00000000000000000000000000000000>:0)
04-07 14:10:18.372 12301 12345 I Unity   : UnityEngine.UI
04-07 14:10:18.372 12301 12345 E Unity   : Exception: [ASSERT] Some other assert happened again!
04-07 14:10:18.372 12301 12345 E Unity   :   at Log.Assert (System.Boolean condition, System.String message) [0x00000] in D:/Dev/Unity/Green Screener 2/Assets/Unity Common/Logging/Log.cs:162
04-07 14:10:18.372 12301 12345 E Unity   :   at Main.HardAssert (MenuItemBase menuItem) [0x00000] in D:/Dev/Unity/Green Screener 2/Assets/App/Main/MainDialogs.cs:264
04-07 14:10:18.372 12301 12345 E Unity   :   at Main.SanitizeImageSourceName (System.String input) [0x00000] in D:/Dev/Unity/Green Screener 2/Assets/App/Main/MainDialogs.cs:100
04-07 14:10:18.372 12301 12345 E Unity   :   at Cysharp.Threading.Tasks.UniTask+ExceptionResultSource`1[T].Finalize () [0x00000] in ./Library/PackageCache/com.cysharp.unitask@73d86259ce/Runtime/UniTask.Factory.cs:290
04-07 14:10:18.372 12301 12345 E Unity   :   at UnityEngine.UIElements.EventCallbackRegistry+DynamicCallbackList.Invoke (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target) [0x00000] in <00000000000000000000000000000000>:0
04-07 14:10:18.372 12301 12345 E Unity   :   at UnityEngine.UIElements.NavigateFocusRing+FocusableHierarchyTraversal.StrictOrder (UnityEngine.UIElements.VisualEleme
04-07 14:10:19.549 12301 12345 I Unity   : Connecting WebSocket
04-07 14:10:20.308 12301 12596 I Unity   : CloudSocket terminated: Unable to connect to the remote server
04-07 14:10:20.328 12301 12345 I Unity   : Scheduling websocket reconnection to 16.8165872945011

We're basically out of ideas, and starting toying with the idea of dropping Sentry for our Unity apps, and just submitting our own crash reports. We've tried what we feel is every combination of settings for:

Any help would be much appreciated.

kahest commented 1 year ago

Hey @perholmes, thanks for the detailled report! We're looking into this, but please be aware that we'll be a bit slower than usual due to ongoing conferences and PTOs.

bitsandfoxes commented 5 months ago

Took a while to get back around to this, sorry about that. We've got a known limitation with CySharp. where we're unable to provide line numbers.

I've tested this a couple of different ways but "it works on my machine". The screenshot you've provided from the stacktrace on a sentry issue is from a native crash. Stacktraces from native crashes get captured through a different mechanism/SDK and look different from C# exceptions and events.

Can you provide me with an example of what it is that does not work for you?

bitsandfoxes commented 5 months ago

Closing this as stale. Please, don't hesitate to reopen this if the issue persists for you.