You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a race condition between the BugsnagUnity.Bugsnag.InternalClient being initialized to a non-null value and attempting to use the InternalClient indirectly via TimingTrackingBehaviour.OnApplicationFocus - the ctor of BugsnagUnity.Client initializes the timing tracker, which means that focus changes that happen after the timing tracker starts but before the ctor finishes and the assignment completes will cause a null reference exception.
Steps to reproduce
This is a race condition with a very narrow window, so the change of reproducing it is low
Call Bugsnag.Start() in Unity to initialize the client
Alt-tab in and out of the Unity window
If the timing lines up, see a NullReferenceException in BugsnagUnity.Bugsnag.SetApplicationState
Environment
Bugsnag version: 7.5.2
Unity version: 2022.3.6f1
iOS/Android/macOS/Windows/browser version: Windows 10
simulator/emulator or physical device: Windows client
Initializing bugsnag via a Unity GameObject or in code?: Code with backing config scriptable object
Player Settings:
Scripting backend (Mono or IL2CPP): IL2CPP
API compatibility level for .NET: .NET Standard 2.1
Stack Trace level for all error types (None/ScriptOnly/Full): Full
Error messages:
NullReferenceException: Object reference not set to an instance of an object
at BugsnagUnity.Bugsnag.SetApplicationState (System.Boolean inFocus) [0x00005] in <de0ea49b4c10449e892e594537b56279>:0
at BugsnagUnity.TimingTrackerBehaviour.OnApplicationFocus (System.Boolean hasFocus) [0x00000] in <de0ea49b4c10449e892e594537b56279>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
BugsnagUnity.BugsnagLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:CallOverridenDebugHandler(Exception, Object)
UnityEngine.SystemInfo:GetDeviceModel()
UnityEngine.SystemInfo:get_deviceModel()
BugsnagUnity.Payload.Device:.ctor(Configuration, String)
BugsnagUnity.SessionTracker:StartManagedSession()
BugsnagUnity.SessionTracker:StartSession()
BugsnagUnity.Client:StartInitialSession()
BugsnagUnity.Client:.ctor(INativeClient)
BugsnagUnity.Bugsnag:Start(Configuration)
... <redacted app frames>
The stack shows that the client was still being constructed (but was past the point of enabling BugsnagUnity.TimingTrackerBehaviour) at the time that Unity broadcast an OnApplicationFocus method, and BugsnagUnity.TimingTrackerBehaviour.OnApplicationFocus ultimately depends on the client being fully constructed.
The text was updated successfully, but these errors were encountered:
Thanks for reaching out and highlighting this issue. We do now have an item on our backlog aimed at investigating this issue further when priority allows.
Once we have more information to share we will be sure to follow up and inform you of any updates.
Describe the bug
There is a race condition between the
BugsnagUnity.Bugsnag.InternalClient
being initialized to a non-null value and attempting to use theInternalClient
indirectly viaTimingTrackingBehaviour.OnApplicationFocus
- the ctor ofBugsnagUnity.Client
initializes the timing tracker, which means that focus changes that happen after the timing tracker starts but before the ctor finishes and the assignment completes will cause a null reference exception.Steps to reproduce
This is a race condition with a very narrow window, so the change of reproducing it is low
Bugsnag.Start()
in Unity to initialize the clientBugsnagUnity.Bugsnag.SetApplicationState
Environment
Error messages:
The stack shows that the client was still being constructed (but was past the point of enabling
BugsnagUnity.TimingTrackerBehaviour
) at the time that Unity broadcast anOnApplicationFocus
method, andBugsnagUnity.TimingTrackerBehaviour.OnApplicationFocus
ultimately depends on the client being fully constructed.The text was updated successfully, but these errors were encountered: