From ffe1423754966c8d2c2776b189737f25fd7656ba Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 11 Apr 2024 13:57:01 +0100 Subject: [PATCH 1/3] handle null status of client The client should not be null at this point. I've added an elvis operator to set application state of the client if it isn't null. I think that this might work to some degree, but it doesn't really handle the race condition. Might be better to add a less performative try/catch block instead. or check the client again to see whether it is null and return a log error. --- src/BugsnagUnity/Bugsnag.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BugsnagUnity/Bugsnag.cs b/src/BugsnagUnity/Bugsnag.cs index 065e8c06a..db826bf56 100644 --- a/src/BugsnagUnity/Bugsnag.cs +++ b/src/BugsnagUnity/Bugsnag.cs @@ -71,7 +71,7 @@ public static bool IsStarted() /// the tracking of in foreground time for the application. /// /// - public static void SetApplicationState(bool inFocus) => Client.SetApplicationState(inFocus); + public static void SetApplicationState(bool inFocus) => Client?.SetApplicationState(inFocus); /// /// Bugsnag uses the concept of contexts to help display and group your errors. From 4048a6bc0dd55a4e4ce7facb14d2cb2ced3c86e8 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 11 Apr 2024 15:04:09 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8269d3e..a04591e8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### TBD + +- Added more null reference checking to the Bugsnag client to prevent crashes when accessing the client before it has been initialised [#788](https://github.com/bugsnag/bugsnag-unity/pull/788) + ## 7.7.3 (2024-04-11) ### Bug Fixes From 9713136893d1725f135c841bc20a4e117bce5838 Mon Sep 17 00:00:00 2001 From: Christian Rafferty <38156512+clr182@users.noreply.github.com> Date: Fri, 3 May 2024 23:28:49 +0100 Subject: [PATCH 3/3] Update src/BugsnagUnity/Bugsnag.cs Updated null check code to suggested code Co-authored-by: Richard Elms --- src/BugsnagUnity/Bugsnag.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BugsnagUnity/Bugsnag.cs b/src/BugsnagUnity/Bugsnag.cs index db826bf56..8a4df502c 100644 --- a/src/BugsnagUnity/Bugsnag.cs +++ b/src/BugsnagUnity/Bugsnag.cs @@ -71,7 +71,13 @@ public static bool IsStarted() /// the tracking of in foreground time for the application. /// /// - public static void SetApplicationState(bool inFocus) => Client?.SetApplicationState(inFocus); + public static void SetApplicationState(bool inFocus) + { + if(Client != null) + { + Client.SetApplicationState(inFocus); + } + } /// /// Bugsnag uses the concept of contexts to help display and group your errors.