Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] UnityEngine.SystemInfo.* should not be called from background threads #173

Open
freerangegreg opened this issue Sep 18, 2019 · 1 comment
Labels
bug Confirmed bug scheduled Work is starting on this feature/bug

Comments

@freerangegreg
Copy link

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.Action3[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
@kattrali
Copy link
Contributor

Thanks for the report, @freerangegreg. This looks like a bug in the Windows implementation of the library.

@kattrali kattrali added backlog We hope to fix this feature/bug in the future bug Confirmed bug labels Sep 18, 2019
@kattrali kattrali changed the title Bugsnag has threading issues with Debug.LogException [Windows] UnityEngine.SystemInfo.* should not be called from background threads Sep 18, 2019
@abigailbramble abigailbramble added scheduled Work is starting on this feature/bug and removed backlog We hope to fix this feature/bug in the future labels Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug scheduled Work is starting on this feature/bug
Projects
None yet
Development

No branches or pull requests

3 participants