From a65e0c295bcb7e1ff0cd2531308ea16aebda0bf7 Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Thu, 8 Jun 2023 19:11:18 +0200 Subject: [PATCH 1/3] PLAT-10165 fixture logging improvements (#716) * initial fixes * line number fix * Update features/fixtures/maze_runner/Assets/Scripts/Main.cs Co-authored-by: Steve Kirkland --------- Co-authored-by: Steve Kirkland --- .buildkite/pipeline.full.yml | 6 ++-- .buildkite/pipeline.yml | 2 +- features/csharp/csharp_events.feature | 14 ++++---- .../maze_runner/Assets/Scripts/Logger.cs | 28 ++++++++++++++++ .../maze_runner/Assets/Scripts/Logger.cs.meta | 11 +++++++ .../maze_runner/Assets/Scripts/Main.cs | 32 ++++++++++++------- features/scripts/build_android.sh | 2 +- src/BugsnagUnity/Client.cs | 4 +++ 8 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 features/fixtures/maze_runner/Assets/Scripts/Logger.cs create mode 100644 features/fixtures/maze_runner/Assets/Scripts/Logger.cs.meta diff --git a/.buildkite/pipeline.full.yml b/.buildkite/pipeline.full.yml index e72b99f8c..4c6f508aa 100644 --- a/.buildkite/pipeline.full.yml +++ b/.buildkite/pipeline.full.yml @@ -200,7 +200,7 @@ steps: - Bugsnag.unitypackage upload: - features/fixtures/maze_runner/mazerunner_2018.4.36f1.apk - - features/fixtures/unity.log + - features/fixtures/build_android_apk.log commands: - rake test:android:build retry: @@ -220,7 +220,7 @@ steps: - Bugsnag.unitypackage upload: - features/fixtures/maze_runner/mazerunner_2019.4.35f1.apk - - features/fixtures/unity.log + - features/fixtures/build_android_apk.log commands: - rake test:android:build retry: @@ -240,7 +240,7 @@ steps: - Bugsnag.unitypackage upload: - features/fixtures/maze_runner/mazerunner_2021.3.13f1.apk - - features/fixtures/unity.log + - features/fixtures/build_android_apk.log commands: - rake test:android:build retry: diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 2ce6ae58f..0826bc4c3 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -127,7 +127,7 @@ steps: - Bugsnag.unitypackage upload: - features/fixtures/maze_runner/mazerunner_2020.3.32f1.apk - - features/fixtures/unity.log + - features/fixtures/build_android_apk.log commands: - rake test:android:build retry: diff --git a/features/csharp/csharp_events.feature b/features/csharp/csharp_events.feature index 92282aff4..fb5a8f17d 100644 --- a/features/csharp/csharp_events.feature +++ b/features/csharp/csharp_events.feature @@ -12,7 +12,7 @@ Feature: csharp events And the event "unhandled" is false And custom metadata is included in the event And the stack frame methods should match: - | NotifySmokeTest.Run() | Main+d__7.MoveNext() | + | NotifySmokeTest.Run() | Main+d__8.MoveNext() | And expected device metadata is included in the event And expected app metadata is included in the event @@ -26,7 +26,7 @@ Feature: csharp events And custom metadata is included in the event And the stack frame methods should match: | UncaughtExceptionSmokeTest.Run() | | - | ScenarioRunner.RunScenario(System.String scenarioName, System.String apiKey, System.String host) | Main+d__7.MoveNext() | + | ScenarioRunner.RunScenario(System.String scenarioName, System.String apiKey, System.String host) | Main+d__8.MoveNext() | And expected device metadata is included in the event And expected app metadata is included in the event @@ -39,7 +39,7 @@ Feature: csharp events And the event "unhandled" is false And custom metadata is included in the event And the stack frame methods should match: - | DebugLogExceptionSmokeTest:Run() | DebugLogExceptionSmokeTest.Run() | d__7:MoveNext() | UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) | + | DebugLogExceptionSmokeTest:Run() | DebugLogExceptionSmokeTest.Run() | d__8:MoveNext() | UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) | | ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) | UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator enumerator, IntPtr returnValueAddress) | And expected device metadata is included in the event And expected app metadata is included in the event @@ -53,7 +53,7 @@ Feature: csharp events And the event "unhandled" is false And custom metadata is included in the event And the stack frame methods should match: - | DebugLogErrorSmokeTest:Run() | DebugLogErrorSmokeTest.Run() | d__7:MoveNext() | | + | DebugLogErrorSmokeTest:Run() | DebugLogErrorSmokeTest.Run() | d__8:MoveNext() | | | ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) | And expected device metadata is included in the event And expected app metadata is included in the event @@ -67,7 +67,7 @@ Feature: csharp events And the event "unhandled" is false And custom metadata is included in the event And the stack frame methods should match: - | DebugLogWarningSmokeTest:Run() | DebugLogWarningSmokeTest.Run() | d__7:MoveNext() | | + | DebugLogWarningSmokeTest:Run() | DebugLogWarningSmokeTest.Run() | d__8:MoveNext() | | | ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) | And expected device metadata is included in the event And expected app metadata is included in the event @@ -81,7 +81,7 @@ Feature: csharp events And the event "unhandled" is false And custom metadata is included in the event And the stack frame methods should match: - | DebugLogSmokeTest:Run() | DebugLogSmokeTest.Run() | d__7:MoveNext() | | + | DebugLogSmokeTest:Run() | DebugLogSmokeTest.Run() | d__8:MoveNext() | | | ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) | And expected device metadata is included in the event And expected app metadata is included in the event @@ -95,7 +95,7 @@ Feature: csharp events And the event "unhandled" is false And custom metadata is included in the event And the stack frame methods should match: - | DebugLogAssertSmokeTest:Run() | DebugLogAssertSmokeTest.Run() | d__7:MoveNext() | | + | DebugLogAssertSmokeTest:Run() | DebugLogAssertSmokeTest.Run() | d__8:MoveNext() | | | ScenarioRunner:RunScenario(String, String, String) | ScenarioRunner.RunScenario(string scenarioName, string apiKey, string host) | ScenarioRunner:RunScenario(string,string,string) | UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) | And expected device metadata is included in the event And expected app metadata is included in the event diff --git a/features/fixtures/maze_runner/Assets/Scripts/Logger.cs b/features/fixtures/maze_runner/Assets/Scripts/Logger.cs new file mode 100644 index 000000000..90706b13f --- /dev/null +++ b/features/fixtures/maze_runner/Assets/Scripts/Logger.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +public class Logger : MonoBehaviour +{ + + const string LOG_PREFIX = "BUGSNAG_MAZERUNNER_LOG : "; + + const string LOG_FILE_NAME = "mazerunner-unity.log"; + + private static string _currentLog; + + public static void I(string msg) + { + Debug.Log(LOG_PREFIX + msg); + _currentLog = msg + "\n"; + WriteLogFile(); + } + + private static void WriteLogFile() + { + var path = Path.Combine(Application.persistentDataPath, LOG_FILE_NAME); + File.WriteAllText(path, _currentLog); + } + +} diff --git a/features/fixtures/maze_runner/Assets/Scripts/Logger.cs.meta b/features/fixtures/maze_runner/Assets/Scripts/Logger.cs.meta new file mode 100644 index 000000000..8cc31f3d0 --- /dev/null +++ b/features/fixtures/maze_runner/Assets/Scripts/Logger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0c0b994281fb547a891f2ecbfc0fadb6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/features/fixtures/maze_runner/Assets/Scripts/Main.cs b/features/fixtures/maze_runner/Assets/Scripts/Main.cs index ed117a226..9bb13f874 100644 --- a/features/fixtures/maze_runner/Assets/Scripts/Main.cs +++ b/features/fixtures/maze_runner/Assets/Scripts/Main.cs @@ -36,11 +36,13 @@ public class Main : MonoBehaviour private const string API_KEY = "a35a2a72bd230ac0aa0f52715bbdc6aa"; private string _mazeHost; + private const int MAX_CONFIG_GET_TRIES = 15; + public ScenarioRunner ScenarioRunner; public IEnumerator Start() { - Debug.Log("Maze Runner app started"); + Log("Maze Runner app started"); yield return GetFixtureConfig(); @@ -56,21 +58,21 @@ private IEnumerator GetFixtureConfig() Application.platform == RuntimePlatform.IPhonePlayer) { var numTries = 0; - while (numTries < 5) + while (numTries < MAX_CONFIG_GET_TRIES) { var configPath = Application.persistentDataPath + _fixtureConfigFileName; if (File.Exists(configPath)) { var configJson = File.ReadAllText(configPath); - Debug.Log("Mazerunner got fixture config json: " + configJson); + Log("Mazerunner got fixture config json: " + configJson); var config = JsonUtility.FromJson(configJson); _mazeHost = "http://" + config.maze_address; break; } else { - Debug.Log("Mazerunner no fixture config found at path: " + configPath); numTries++; + Log(string.Format("Maze Runner did not find the config file at path {0} try number {1}", configPath, numTries)); yield return new WaitForSeconds(1); } } @@ -78,6 +80,7 @@ private IEnumerator GetFixtureConfig() if (string.IsNullOrEmpty(_mazeHost)) { + Log("Host not set from config file, using hard coded"); _mazeHost = "http://localhost:9339"; if (Application.platform == RuntimePlatform.IPhonePlayer || @@ -86,7 +89,7 @@ private IEnumerator GetFixtureConfig() _mazeHost = "http://bs-local.com:9339"; } } - Debug.Log("Mazerunner host set to: " + _mazeHost); + Log("Mazerunner host set to: " + _mazeHost); } private void DoRunNextMazeCommand() @@ -97,7 +100,7 @@ private void DoRunNextMazeCommand() IEnumerator RunNextMazeCommand() { var url = _mazeHost + "/command"; - Console.WriteLine("RunNextMazeCommand called, requesting command from: {0}", url); + Log("Requesting maze command from: " + url); using (UnityWebRequest request = UnityWebRequest.Get(url)) { yield return request.SendWebRequest(); @@ -109,23 +112,23 @@ IEnumerator RunNextMazeCommand() !request.isNetworkError; #endif - Console.WriteLine("result is " + result); + Log("result is " + result); if (result) { var response = request.downloadHandler?.text; - Console.WriteLine("Raw response: " + response); + Log("Raw response: " + response); if (response == null || response == "null" || response == "No commands to provide") { - Console.WriteLine("No Maze Runner command to process at present"); + Log("No Maze Runner command to process at present"); } else { var command = JsonUtility.FromJson(response); if (command != null) { - Console.WriteLine("Received Maze Runner command:"); - Console.WriteLine("Action: " + command.action); - Console.WriteLine("Scenario: " + command.scenarioName); + Log("Received Maze Runner command:"); + Log("Action: " + command.action); + Log("Scenario: " + command.scenarioName); if ("clear_cache".Equals(command.action)) { @@ -178,6 +181,11 @@ public static void ClearIOSData() #endif } + private static void Log(string msg) + { + Logger.I(msg); + } + } diff --git a/features/scripts/build_android.sh b/features/scripts/build_android.sh index e9c2105ea..958e730ef 100755 --- a/features/scripts/build_android.sh +++ b/features/scripts/build_android.sh @@ -15,7 +15,7 @@ popd pushd "$script_path/../fixtures" # Run unity and immediately exit afterwards, log all output -DEFAULT_CLI_ARGS="-quit -batchmode -nographics -logFile unity.log" +DEFAULT_CLI_ARGS="-quit -batchmode -nographics -logFile build_android_apk.log" project_path=`pwd`/maze_runner diff --git a/src/BugsnagUnity/Client.cs b/src/BugsnagUnity/Client.cs index a3aa67974..c69cde11e 100644 --- a/src/BugsnagUnity/Client.cs +++ b/src/BugsnagUnity/Client.cs @@ -290,6 +290,10 @@ private void NotifyFromUnityLog(string condition, string stackTrace, LogType log { return; } + if (condition.StartsWith("BUGSNAG_MAZERUNNER_LOG")) + { + return; + } if (Configuration.AutoDetectErrors && logType.IsGreaterThanOrEqualTo(Configuration.NotifyLogLevel)) { var logMessage = new UnityLogMessage(condition, stackTrace, logType); From 562563592e5c6608b6dc624ba8f27c5a43eee7cf Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Thu, 8 Jun 2023 20:42:37 +0200 Subject: [PATCH 2/3] PLAT-10216 prevent JNI call for session and event callbacks if not used (#717) --- CHANGELOG.md | 6 ++++ .../Android/AndroidBackgroundJVMSmokeTest.cs | 1 + .../Scenarios/iOS/IosNativeException.cs | 1 + src/BugsnagUnity.m | 6 ++++ src/BugsnagUnity/Client.cs | 6 +++- src/BugsnagUnity/INativeClient.cs | 5 +++ .../Native/Android/NativeClient.cs | 5 +++ .../Native/Android/NativeInterface.cs | 32 ++++++++++++++++--- src/BugsnagUnity/Native/Cocoa/NativeClient.cs | 28 ++++++++++++++-- src/BugsnagUnity/Native/Cocoa/NativeCode.cs | 3 ++ .../Native/Fallback/NativeClient.cs | 5 +++ .../Native/Windows/NativeClient.cs | 5 +++ 12 files changed, 96 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f54147005..72a699980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## TBD + +## Bug Fixes + +- Prevent callback to Unity from native layers for session and event callbacks if not used. [#717](https://github.com/bugsnag/bugsnag-unity/pull/717) + ## 7.6.0 (2023-05-25) - Update bugsnag-cocoa from v6.25.2 to [v6.26.2](https://github.com/bugsnag/bugsnag-cocoa/blob/master/CHANGELOG.md#6262-2023-04-20) diff --git a/features/fixtures/maze_runner/Assets/Scripts/Scenarios/Android/AndroidBackgroundJVMSmokeTest.cs b/features/fixtures/maze_runner/Assets/Scripts/Scenarios/Android/AndroidBackgroundJVMSmokeTest.cs index 1c2c98c11..2d155d4e8 100644 --- a/features/fixtures/maze_runner/Assets/Scripts/Scenarios/Android/AndroidBackgroundJVMSmokeTest.cs +++ b/features/fixtures/maze_runner/Assets/Scripts/Scenarios/Android/AndroidBackgroundJVMSmokeTest.cs @@ -10,6 +10,7 @@ public override void PrepareConfig(string apiKey, string host) base.PrepareConfig(apiKey, host); Configuration.SetUser("1", "2", "3"); Configuration.ProjectPackages = new string[] { "test.test.test" }; + Configuration.AddOnSession((s) => { return true; }); } public override void Run() diff --git a/features/fixtures/maze_runner/Assets/Scripts/Scenarios/iOS/IosNativeException.cs b/features/fixtures/maze_runner/Assets/Scripts/Scenarios/iOS/IosNativeException.cs index e7e10ef9e..4f09a4f19 100644 --- a/features/fixtures/maze_runner/Assets/Scripts/Scenarios/iOS/IosNativeException.cs +++ b/features/fixtures/maze_runner/Assets/Scripts/Scenarios/iOS/IosNativeException.cs @@ -5,6 +5,7 @@ public class IosNativeException : Scenario public override void PrepareConfig(string apiKey, string host) { base.PrepareConfig(apiKey, host); + Configuration.AddOnSession((s) => { return true; }); } public override void Run() diff --git a/src/BugsnagUnity.m b/src/BugsnagUnity.m index 593291ddf..8afd58ad5 100644 --- a/src/BugsnagUnity.m +++ b/src/BugsnagUnity.m @@ -390,6 +390,12 @@ void bugsnag_markLaunchCompleted() { [Bugsnag markLaunchCompleted]; } +void bugsnag_registerForSessionCallbacksAfterStart(bool (*callback)(void *session)){ + [Bugsnag addOnSessionBlock:^BOOL (BugsnagSession *session) { + return callback((__bridge void *)session); + }]; +} + void *bugsnag_createConfiguration(char *apiKey) { return (void *)CFBridgingRetain([[BugsnagConfiguration alloc] initWithApiKey:@(apiKey)]); } diff --git a/src/BugsnagUnity/Client.cs b/src/BugsnagUnity/Client.cs index c69cde11e..36947b2d5 100644 --- a/src/BugsnagUnity/Client.cs +++ b/src/BugsnagUnity/Client.cs @@ -579,7 +579,11 @@ public string GetContext() public void RemoveOnError(Func bugsnagCallback) => Configuration.RemoveOnError(bugsnagCallback); - public void AddOnSession(Func callback) => Configuration.AddOnSession(callback); + public void AddOnSession(Func callback) + { + Configuration.AddOnSession(callback); + NativeClient.RegisterForOnSessionCallbacks(); + } public void RemoveOnSession(Func callback) => Configuration.RemoveOnSession(callback); diff --git a/src/BugsnagUnity/INativeClient.cs b/src/BugsnagUnity/INativeClient.cs index 59e19188b..c2f7a6f6d 100644 --- a/src/BugsnagUnity/INativeClient.cs +++ b/src/BugsnagUnity/INativeClient.cs @@ -104,5 +104,10 @@ interface INativeClient : IFeatureFlagStore bool ShouldAttemptDelivery(); + /// + /// Subscribes the Unity layer for session callbacks. Not many users use session callbacks, so we are only subscribing to the native side if necessary as an optimisation. + /// + void RegisterForOnSessionCallbacks(); + } } diff --git a/src/BugsnagUnity/Native/Android/NativeClient.cs b/src/BugsnagUnity/Native/Android/NativeClient.cs index c225ae0f5..183bdec64 100644 --- a/src/BugsnagUnity/Native/Android/NativeClient.cs +++ b/src/BugsnagUnity/Native/Android/NativeClient.cs @@ -156,6 +156,11 @@ public bool ShouldAttemptDelivery() { return true; } + + public void RegisterForOnSessionCallbacks() + { + NativeInterface.RegisterForOnSessionCallbacks(); + } } } diff --git a/src/BugsnagUnity/Native/Android/NativeInterface.cs b/src/BugsnagUnity/Native/Android/NativeInterface.cs index 10f0dc72d..6f16518a6 100644 --- a/src/BugsnagUnity/Native/Android/NativeInterface.cs +++ b/src/BugsnagUnity/Native/Android/NativeInterface.cs @@ -64,13 +64,15 @@ class NativeInterface - + private Configuration _configuration; private bool CanRunOnBackgroundThread; private static bool Unity2019OrNewer; private Thread MainThread; + private bool _registeredForSessionCallbacks; + private class OnSessionCallback : AndroidJavaProxy { @@ -135,6 +137,7 @@ public bool onSend(AndroidJavaObject @event) public NativeInterface(Configuration cfg) { + _configuration = cfg; AndroidJavaObject config = CreateNativeConfig(cfg); Unity2019OrNewer = IsUnity2019OrNewer(); MainThread = Thread.CurrentThread; @@ -331,9 +334,15 @@ AndroidJavaObject CreateNativeConfig(Configuration config) } //Register for callbacks - obj.Call("addOnSession", new OnSessionCallback(config)); - obj.Call("addOnSend", new OnSendErrorCallback(config)); - + if (config.GetOnSessionCallbacks() != null && config.GetOnSessionCallbacks().Count > 0) + { + obj.Call("addOnSession", new OnSessionCallback(config)); + _registeredForSessionCallbacks = true; + } + if (config.GetOnSendErrorCallbacks() != null && config.GetOnSendErrorCallbacks().Count > 0) + { + obj.Call("addOnSend", new OnSendErrorCallback(config)); + } // set endpoints var notify = config.Endpoints.Notify.ToString(); @@ -1200,5 +1209,20 @@ public void ClearFeatureFlags() AndroidJNI.CallVoidMethod(GetClientRef(), ClearFeatureFlagsMethod, null); } + public void RegisterForOnSessionCallbacks() + { + if (_registeredForSessionCallbacks || _configuration == null) + { + return; + } + + var addOnSessionmethodId = AndroidJNI.GetMethodID(ClientClass, "addOnSession", "(Lcom/bugsnag/android/OnSessionCallback;)V"); + var callback = new OnSessionCallback(_configuration); + object[] args = new object[] { callback }; + jvalue[] jargs = AndroidJNIHelper.CreateJNIArgArray(args); + AndroidJNI.CallVoidMethod(GetClientRef(), addOnSessionmethodId, jargs); + _registeredForSessionCallbacks = true; + } + } } diff --git a/src/BugsnagUnity/Native/Cocoa/NativeClient.cs b/src/BugsnagUnity/Native/Cocoa/NativeClient.cs index 353252b02..eb5e1b55a 100644 --- a/src/BugsnagUnity/Native/Cocoa/NativeClient.cs +++ b/src/BugsnagUnity/Native/Cocoa/NativeClient.cs @@ -16,6 +16,7 @@ class NativeClient : INativeClient private static Session _nativeSession; IntPtr NativeConfiguration { get; } private static NativeClient _instance; + private bool _registeredForSessionCallbacks; public NativeClient(Configuration configuration) { @@ -49,8 +50,21 @@ IntPtr CreateNativeConfig(Configuration config) NativeCode.bugsnag_setAutoTrackSessions(obj, config.AutoTrackSessions); NativeCode.bugsnag_setLaunchDurationMillis(obj, (ulong)config.LaunchDurationMillis); NativeCode.bugsnag_setSendLaunchCrashesSynchronously(obj,config.SendLaunchCrashesSynchronously); - NativeCode.bugsnag_registerForOnSendCallbacks(obj, HandleOnSendCallbacks); - NativeCode.bugsnag_registerForSessionCallbacks(obj, HandleSessionCallbacks); + + if (config.GetOnSendErrorCallbacks() != null && config.GetOnSendErrorCallbacks().Count > 0) + { + NativeCode.bugsnag_registerForOnSendCallbacks(obj, HandleOnSendCallbacks); + } + + if (config.GetOnSessionCallbacks() != null && config.GetOnSessionCallbacks().Count > 0) + { + _registeredForSessionCallbacks = true; + NativeCode.bugsnag_registerForSessionCallbacks(obj, HandleSessionCallbacks); + } + + + + NativeCode.bugsnag_setAppHangThresholdMillis(obj, config.AppHangThresholdMillis); NativeCode.bugsnag_setMaxStringValueLength(obj, config.MaxStringValueLength); AddFeatureFlagsToConfig(obj,config); @@ -449,5 +463,15 @@ public bool ShouldAttemptDelivery() { return true; } + + public void RegisterForOnSessionCallbacks() + { + if (_registeredForSessionCallbacks) + { + return; + } + _registeredForSessionCallbacks = true; + NativeCode.bugsnag_registerForSessionCallbacksAfterStart(HandleSessionCallbacks); + } } } diff --git a/src/BugsnagUnity/Native/Cocoa/NativeCode.cs b/src/BugsnagUnity/Native/Cocoa/NativeCode.cs index 65756db84..f004f292b 100644 --- a/src/BugsnagUnity/Native/Cocoa/NativeCode.cs +++ b/src/BugsnagUnity/Native/Cocoa/NativeCode.cs @@ -37,6 +37,9 @@ partial class NativeCode [DllImport(Import)] internal static extern void bugsnag_registerForSessionCallbacks(IntPtr configuration, Func callback); + [DllImport(Import)] + internal static extern void bugsnag_registerForSessionCallbacksAfterStart(Func callback); + internal delegate void SessionInformation(IntPtr instance, string sessionId, string startedAt, int handled, int unhandled); [DllImport(Import)] internal static extern void bugsnag_retrieveCurrentSession(IntPtr instance, SessionInformation callback); diff --git a/src/BugsnagUnity/Native/Fallback/NativeClient.cs b/src/BugsnagUnity/Native/Fallback/NativeClient.cs index 89cac8ce3..b57a08212 100644 --- a/src/BugsnagUnity/Native/Fallback/NativeClient.cs +++ b/src/BugsnagUnity/Native/Fallback/NativeClient.cs @@ -164,5 +164,10 @@ public bool ShouldAttemptDelivery() { return true; } + + public void RegisterForOnSessionCallbacks() + { + // Not Used on this platform + } } } diff --git a/src/BugsnagUnity/Native/Windows/NativeClient.cs b/src/BugsnagUnity/Native/Windows/NativeClient.cs index cdbf16e47..85d985019 100644 --- a/src/BugsnagUnity/Native/Windows/NativeClient.cs +++ b/src/BugsnagUnity/Native/Windows/NativeClient.cs @@ -211,5 +211,10 @@ public bool ShouldAttemptDelivery() { return true; } + + public void RegisterForOnSessionCallbacks() + { + // Not Used on this platform + } } } From 845266e43c8d7aa8304ad6c0b3b721293a2545fc Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Tue, 13 Jun 2023 06:53:38 +0200 Subject: [PATCH 3/3] Release v7.6.1 --- CHANGELOG.md | 4 ++-- build.cake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72a699980..53b49df6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ # Changelog -## TBD +## 7.6.1 (2023-06-13) ## Bug Fixes -- Prevent callback to Unity from native layers for session and event callbacks if not used. [#717](https://github.com/bugsnag/bugsnag-unity/pull/717) +- Prevent callback to Unity from native layers for session and event callbacks if not used to avoid potential ANRs and improve performance. [#717](https://github.com/bugsnag/bugsnag-unity/pull/717) ## 7.6.0 (2023-05-25) diff --git a/build.cake b/build.cake index 9af497f45..13ddc6854 100644 --- a/build.cake +++ b/build.cake @@ -5,7 +5,7 @@ var target = Argument("target", "Default"); var solution = File("./BugsnagUnity.sln"); var configuration = Argument("configuration", "Release"); var project = File("./src/BugsnagUnity/BugsnagUnity.csproj"); -var version = "7.6.0"; +var version = "7.6.1"; Task("Restore-NuGet-Packages") .Does(() => NuGetRestore(solution));