Exceptions on background thread are not handled and reported correctly
See original GitHub issueEnvironment
How do you use Sentry? sentry.io
Which version of the SDK? 0.20.1
How did you install the package? UPM, git-url
Which version of Unity? 2021.3.6f1 LTS
Is this happening in Unity (editor) or on a player like Android, iOS, Windows? Reproduced in Windows Editor and Windows Player
Steps to Reproduce
- Create a new empty Unity project.
- Import sentry-unity 0.20.1 in UPM.
- Attach the code below to a GameObject
- Start the game
- Throw some exceptions in a background thread (click the in-game button).
Expected Result
Exceptions are reported as events to sentry.io
Actual Result
Only the first exception is handled and reported correctly.
Something seems to go wrong within the SDK, because after the first exception, subsequent exceptions do not result in any debug logs from Sentry, except a single “Sentry: (Info) Disposing the Hub”, which is directly followed by:
exception inside UnhandledException handler: (null) assembly:C:\Program Files\Unity\Hub\Editor\2021.3.6f1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit-win32\mscorlib.dll type:Exception member:(null)
Code
using System;
using System.Threading;
using UnityEngine;
public class SentryTest : MonoBehaviour
{
void OnGUI()
{
if (GUILayout.Button("Throw Exception On Background Thread"))
{
Debug.Log("Pressed button");
var thread = new Thread(() =>
{
Thread.Sleep(1000);
Debug.Log("Will throw exception");
throw new Exception("Testing Background Thread Crash 2");
});
thread.Start();
}
}
}
Any logs or screenshots
Issue Analytics
- State:
- Created a year ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
@DrummerB thanks for raising this and providing the snippet. I can reproduce the issue locally and we’re going to take a look!
Great, thanks for the fix!