bugsnag-unity
bugsnag-unity copied to clipboard
[Windows] UnityEngine.SystemInfo.* should not be called from background threads
Description
Bugsnag-unity hooks into the log callback, looking for exceptions. When it handles an exception, it queries Unity for information about the current device. These calls are not allowed to be called at certain times: (1) when not on the main thread and (2) when Unity is calling constructors or field initializers.
Debug.LogException triggers this callback, and Debug.LogException is allowed to be called from anywhere, including other threads (as are all the Debug.Log* methods).
I would suggest that you move any Unity calls into initialization, rather than doing it every time you catch an exception, and look for other possible threading problems in the exception handler.
Issue
Here's a stack trace of such an event. (This is from an il2cpp release build, so there are no line numbers.)
UnityException: GetDeviceModel can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
at BugsnagUnity.NativeClient.PopulateDevice (BugsnagUnity.Payload.Device device) [0x00000] in <00000000000000000000000000000000>:0
at BugsnagUnity.Client.Notify (BugsnagUnity.Payload.Exception[] exceptions, BugsnagUnity.Payload.HandledState handledState, BugsnagUnity.Middleware callback, System.Nullable1[T] logType) [0x00000] in <00000000000000000000000000000000>:0 at BugsnagUnity.Client.Notify (System.String condition, System.String stackTrace, UnityEngine.LogType logType) [0x00000] in <00000000000000000000000000000000>:0 at BugsnagUnity.Client.MultiThreadedNotify (System.String condition, System.String stackTrace, UnityEngine.LogType logType) [0x00000] in <00000000000000000000000000000000>:0 at System.Action
3[T1,T2,T3].Invoke (T1 arg1, T2 arg2, T3 arg3) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Application.CallLogCallback (System.String logString, System.String stackTrace, UnityEngine.LogType type, System.Boolean invokedOnMainThread) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Logger.LogException (System.Exception exception, UnityEngine.Object context) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Debug.LogException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0
Environment
- bugsnag-unity version: 4.6.1
- Unity version: 2018.4.5
- Operating system name and version: Windows 10
- Target platform names and versions: Probably all of them
- Initializing bugsnag via the Unity UI or in code? In code
Thanks for the report, @freerangegreg. This looks like a bug in the Windows implementation of the library.