From 7545dffa10398da9d7f30dc76da011e48822ffaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Zakrzewski?= Date: Wed, 5 Apr 2023 08:22:40 +0200 Subject: [PATCH 1/6] Add XBOX support. --- Editor/BacktraceConfigurationEditor.cs | 6 +- .../BacktraceDatabaseConfigurationEditor.cs | 2 +- Runtime/Model/BacktraceConfiguration.cs | 4 +- .../BacktraceDatabaseAttachmentManager.cs | 2 +- .../Database/BacktraceDatabaseSettings.cs | 4 +- Runtime/Native/Base/NativeClientBase.cs | 2 +- Runtime/Native/NativeClientFactory.cs | 2 + Runtime/Native/XBOX.meta | 8 + Runtime/Native/XBOX/NativeClient.cs | 140 ++++++++++++++++++ Runtime/Native/XBOX/NativeClient.cs.meta | 11 ++ 10 files changed, 171 insertions(+), 10 deletions(-) create mode 100644 Runtime/Native/XBOX.meta create mode 100644 Runtime/Native/XBOX/NativeClient.cs create mode 100644 Runtime/Native/XBOX/NativeClient.cs.meta diff --git a/Editor/BacktraceConfigurationEditor.cs b/Editor/BacktraceConfigurationEditor.cs index 1b8d4670..07d32483 100644 --- a/Editor/BacktraceConfigurationEditor.cs +++ b/Editor/BacktraceConfigurationEditor.cs @@ -132,12 +132,12 @@ public override void OnInspectorGUI() showNativeCrashesSettings = EditorGUILayout.Foldout(showNativeCrashesSettings, BacktraceConfigurationLabels.LABEL_NATIVE_CRASHES, showNativeCrashesSupportFoldout); if (showNativeCrashesSettings) { -#if UNITY_STANDALONE_WIN +#if UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES DrawMultiselectDropdown("MinidumpType", BacktraceConfigurationLabels.LABEL_MINIDUMP_SUPPORT, serializedObject); #endif -#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN +#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES SerializedProperty captureNativeCrashes = serializedObject.FindProperty("CaptureNativeCrashes"); EditorGUILayout.PropertyField( captureNativeCrashes, @@ -189,7 +189,7 @@ public override void OnInspectorGUI() } } -#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN +#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES EditorGUILayout.PropertyField( serializedObject.FindProperty("AddUnityLogToReport"), new GUIContent(BacktraceConfigurationLabels.LABEL_ADD_UNITY_LOG)); diff --git a/Editor/BacktraceDatabaseConfigurationEditor.cs b/Editor/BacktraceDatabaseConfigurationEditor.cs index 3688b10b..2bd50846 100644 --- a/Editor/BacktraceDatabaseConfigurationEditor.cs +++ b/Editor/BacktraceDatabaseConfigurationEditor.cs @@ -20,7 +20,7 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("Please insert valid Backtrace database path!", MessageType.Error); } -#if UNITY_STANDALONE_WIN +#if UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES settings.MinidumpType = (MiniDumpType)EditorGUILayout.EnumFlagsField(BacktraceConfigurationLabels.LABEL_MINIDUMP_SUPPORT, settings.MinidumpType); #else settings.MinidumpType = MiniDumpType.None; diff --git a/Runtime/Model/BacktraceConfiguration.cs b/Runtime/Model/BacktraceConfiguration.cs index 2053af50..34e8dbb5 100644 --- a/Runtime/Model/BacktraceConfiguration.cs +++ b/Runtime/Model/BacktraceConfiguration.cs @@ -125,13 +125,13 @@ public class BacktraceConfiguration : ScriptableObject [Tooltip("Try to find game native crashes and send them on Game startup")] public bool SendUnhandledGameCrashesOnGameStartup = true; -#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN +#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES #if UNITY_ANDROID /// /// Capture native NDK Crashes. /// [Tooltip("Capture native NDK Crashes (ANDROID API 21+)")] -#elif UNITY_IOS || UNITY_STANDALONE_WIN +#elif UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES /// /// Capture native crashes. /// diff --git a/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs b/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs index 6900322b..6f779a8b 100644 --- a/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs +++ b/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs @@ -175,7 +175,7 @@ private string GetUnityPlayerLogFile(BacktraceData backtraceData, string dataPre string.Format("~/.config/unity3d/{0}/{1}/Player.log", Application.companyName, Application.productName); #elif UNITY_STANDALONE_OSX string.Format("~/Library/Logs/{0}/{1}/Player.log", Application.companyName, Application.productName); -#elif UNITY_STANDALONE_WIN +#elif UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES Path.Combine( Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)).FullName, string.Format("LocalLow/{0}/{1}/Player.log", Application.companyName, Application.productName)); diff --git a/Runtime/Model/Database/BacktraceDatabaseSettings.cs b/Runtime/Model/Database/BacktraceDatabaseSettings.cs index bd050166..3ff966ef 100644 --- a/Runtime/Model/Database/BacktraceDatabaseSettings.cs +++ b/Runtime/Model/Database/BacktraceDatabaseSettings.cs @@ -114,7 +114,7 @@ public bool AddUnityLogToReport { get { -#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN +#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES return _configuration.AddUnityLogToReport; #else return false; @@ -135,7 +135,7 @@ public MiniDumpType MinidumpType get { -#if UNITY_STANDALONE_WIN +#if UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES return _configuration.MinidumpType; #else return MiniDumpType.None; diff --git a/Runtime/Native/Base/NativeClientBase.cs b/Runtime/Native/Base/NativeClientBase.cs index 17155914..607698ac 100644 --- a/Runtime/Native/Base/NativeClientBase.cs +++ b/Runtime/Native/Base/NativeClientBase.cs @@ -1,4 +1,4 @@ -#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN +#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES using Backtrace.Unity.Model; using Backtrace.Unity.Model.Breadcrumbs; using Backtrace.Unity.Extensions; diff --git a/Runtime/Native/NativeClientFactory.cs b/Runtime/Native/NativeClientFactory.cs index 94cd8ea8..ec226d3e 100644 --- a/Runtime/Native/NativeClientFactory.cs +++ b/Runtime/Native/NativeClientFactory.cs @@ -10,6 +10,8 @@ internal static INativeClient CreateNativeClient(BacktraceConfiguration configur { #if UNITY_EDITOR return null; +#elif UNITY_GAMECORE_XBOXSERIES + return new XBOX.NativeClient(configuration, breadcrumbs, attributes, attachments); #elif UNITY_STANDALONE_WIN return new Windows.NativeClient(configuration, breadcrumbs, attributes, attachments); #elif UNITY_ANDROID diff --git a/Runtime/Native/XBOX.meta b/Runtime/Native/XBOX.meta new file mode 100644 index 00000000..d8deacc3 --- /dev/null +++ b/Runtime/Native/XBOX.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 83e57ee60f68fe64fa6067e9d8b0d094 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Native/XBOX/NativeClient.cs b/Runtime/Native/XBOX/NativeClient.cs new file mode 100644 index 00000000..8f4312e8 --- /dev/null +++ b/Runtime/Native/XBOX/NativeClient.cs @@ -0,0 +1,140 @@ +#if UNITY_GAMECORE_XBOXSERIES +using Backtrace.Unity.Interfaces; +using Backtrace.Unity.Model; +using Backtrace.Unity.Model.Breadcrumbs; +using Backtrace.Unity.Runtime.Native.Base; +using Backtrace.Unity.Types; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Backtrace.Unity.Tests.Runtime")] +namespace Backtrace.Unity.Runtime.Native.XBOX +{ + + internal class NativeClient : NativeClientBase, INativeClient + { + [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + private static extern bool BacktraceCrash(); + + [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + private static extern bool BacktraceAddAttribute( + [MarshalAs(UnmanagedType.LPWStr)] string name, + [MarshalAs(UnmanagedType.LPWStr)] string value + ); + + [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + private static extern bool BacktraceAddFile( + [MarshalAs(UnmanagedType.LPWStr)] string name, + [MarshalAs(UnmanagedType.LPWStr)] string path + ); + + [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + private static extern bool BacktraceSetUrl( + [MarshalAs(UnmanagedType.LPWStr)] string url + ); + + [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + private static extern bool BacktraceBreakpadInitialized(); + + [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + private static extern bool BacktraceInitializeBreakpad(); + + /// + /// Determine if the XBOX integration should be enabled + /// + private bool _enabled = +#if UNITY_GAMECORE_XBOXSERIES && !UNITY_EDITOR + true; +#else + false; +#endif + + public NativeClient(BacktraceConfiguration configuration, BacktraceBreadcrumbs breadcrumbs, IDictionary clientAttributes, IEnumerable attachments) : base(configuration, breadcrumbs) + { + if (!_enabled) + { + return; + } + AddScopedAttributes(clientAttributes); + HandleNativeCrashes(clientAttributes, attachments); + if (!configuration.ReportFilterType.HasFlag(ReportFilterType.Hang)) + { + HandleAnr(); + } + } + + internal void AddScopedAttributes(IDictionary attributes) + { + foreach (var attribute in attributes) + { + if (attribute.Key == null || attribute.Value == null) + { + continue; + } + + BacktraceAddAttribute(attribute.Key, attribute.Value); + } + } + + private void HandleNativeCrashes(IDictionary clientAttributes, IEnumerable attachments) + { + var integrationDisabled = !_configuration.CaptureNativeCrashes || !_configuration.Enabled; + if (integrationDisabled) + { + return; + } + + var minidumpUrl = new BacktraceCredentials(_configuration.GetValidServerUrl()).GetMinidumpSubmissionUrl().ToString(); + foreach (var attachment in attachments) + { + var name = Path.GetFileName(attachment); + BacktraceAddFile(name, attachment); + } + + BacktraceSetUrl(minidumpUrl); + CaptureNativeCrashes = BacktraceInitializeBreakpad(); + + if (!CaptureNativeCrashes) + { + Debug.LogWarning("Backtrace native integration status: Cannot initialize Crashpad client"); + return; + } + } + + public void GetAttributes(IDictionary attributes) + { + throw new NotImplementedException(); + } + + public void HandleAnr() + { + throw new NotImplementedException(); + } + + public bool OnOOM() + { + throw new NotImplementedException(); + } + + public void SetAttribute(string key, string value) + { + if (string.IsNullOrEmpty(key)) + { + return; + } + // avoid null reference in crashpad source code + if (value == null) + { + value = string.Empty; + } + BacktraceAddAttribute(key, value); + } + } +} +#endif \ No newline at end of file diff --git a/Runtime/Native/XBOX/NativeClient.cs.meta b/Runtime/Native/XBOX/NativeClient.cs.meta new file mode 100644 index 00000000..385b93ae --- /dev/null +++ b/Runtime/Native/XBOX/NativeClient.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c024e46a74897f442b0eadfcc3187dfb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From cf0e54495f03fae09a75da838f5cf923af449be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Zakrzewski?= Date: Tue, 11 Apr 2023 23:32:42 +0200 Subject: [PATCH 2/6] Respond to comments from Konrad --- Editor/BacktraceConfigurationEditor.cs | 2 +- .../Database/BacktraceDatabaseAttachmentManager.cs | 2 +- Runtime/Native/XBOX/NativeClient.cs | 14 +++++--------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Editor/BacktraceConfigurationEditor.cs b/Editor/BacktraceConfigurationEditor.cs index 07d32483..ea1110e6 100644 --- a/Editor/BacktraceConfigurationEditor.cs +++ b/Editor/BacktraceConfigurationEditor.cs @@ -132,7 +132,7 @@ public override void OnInspectorGUI() showNativeCrashesSettings = EditorGUILayout.Foldout(showNativeCrashesSettings, BacktraceConfigurationLabels.LABEL_NATIVE_CRASHES, showNativeCrashesSupportFoldout); if (showNativeCrashesSettings) { -#if UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES +#if UNITY_STANDALONE_WIN DrawMultiselectDropdown("MinidumpType", BacktraceConfigurationLabels.LABEL_MINIDUMP_SUPPORT, serializedObject); #endif diff --git a/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs b/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs index 6f779a8b..6900322b 100644 --- a/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs +++ b/Runtime/Model/Database/BacktraceDatabaseAttachmentManager.cs @@ -175,7 +175,7 @@ private string GetUnityPlayerLogFile(BacktraceData backtraceData, string dataPre string.Format("~/.config/unity3d/{0}/{1}/Player.log", Application.companyName, Application.productName); #elif UNITY_STANDALONE_OSX string.Format("~/Library/Logs/{0}/{1}/Player.log", Application.companyName, Application.productName); -#elif UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES +#elif UNITY_STANDALONE_WIN Path.Combine( Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)).FullName, string.Format("LocalLow/{0}/{1}/Player.log", Application.companyName, Application.productName)); diff --git a/Runtime/Native/XBOX/NativeClient.cs b/Runtime/Native/XBOX/NativeClient.cs index 8f4312e8..efca92a8 100644 --- a/Runtime/Native/XBOX/NativeClient.cs +++ b/Runtime/Native/XBOX/NativeClient.cs @@ -39,9 +39,6 @@ private static extern bool BacktraceSetUrl( [MarshalAs(UnmanagedType.LPWStr)] string url ); - [DllImport("breakpad_xbox_simplified_abi_mt.dll")] - private static extern bool BacktraceBreakpadInitialized(); - [DllImport("breakpad_xbox_simplified_abi_mt.dll")] private static extern bool BacktraceInitializeBreakpad(); @@ -73,7 +70,7 @@ internal void AddScopedAttributes(IDictionary attributes) { foreach (var attribute in attributes) { - if (attribute.Key == null || attribute.Value == null) + if (string.IsNullOrEmpty(attribute.Key) || attribute.Value == null) { continue; } @@ -91,35 +88,34 @@ private void HandleNativeCrashes(IDictionary clientAttributes, I } var minidumpUrl = new BacktraceCredentials(_configuration.GetValidServerUrl()).GetMinidumpSubmissionUrl().ToString(); + BacktraceSetUrl(minidumpUrl); + foreach (var attachment in attachments) { var name = Path.GetFileName(attachment); BacktraceAddFile(name, attachment); } - BacktraceSetUrl(minidumpUrl); CaptureNativeCrashes = BacktraceInitializeBreakpad(); if (!CaptureNativeCrashes) { - Debug.LogWarning("Backtrace native integration status: Cannot initialize Crashpad client"); + Debug.LogWarning("Backtrace native integration status: Cannot initialize the Breakpad client"); return; } } public void GetAttributes(IDictionary attributes) { - throw new NotImplementedException(); } public void HandleAnr() { - throw new NotImplementedException(); } public bool OnOOM() { - throw new NotImplementedException(); + return false; } public void SetAttribute(string key, string value) From 875b78932da8491cbbf4ce01b901a7409c112574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Zakrzewski?= Date: Fri, 14 Apr 2023 19:57:46 +0200 Subject: [PATCH 3/6] Respond to comments, should be all ok by now. --- Editor/BacktraceConfigurationEditor.cs | 5 +- .../BacktraceDatabaseConfigurationEditor.cs | 2 +- Runtime/Model/BacktraceConfiguration.cs | 2 + .../Database/BacktraceDatabaseSettings.cs | 4 +- Runtime/Native/XBOX/NativeClient.cs | 72 +++++++++---------- 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Editor/BacktraceConfigurationEditor.cs b/Editor/BacktraceConfigurationEditor.cs index ea1110e6..153425cc 100644 --- a/Editor/BacktraceConfigurationEditor.cs +++ b/Editor/BacktraceConfigurationEditor.cs @@ -148,10 +148,11 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("You're using Backtrace-Unity integration with Unity 16b NDK support. Please contact Backtrace support for any additional help", MessageType.Warning); } #endif - +#if !UNITY_GAMECORE_XBOXSERIES EditorGUILayout.PropertyField( serializedObject.FindProperty("HandleANR"), new GUIContent(BacktraceConfigurationLabels.LABEL_HANDLE_ANR)); +#endif #if UNITY_ANDROID || UNITY_IOS EditorGUILayout.PropertyField( serializedObject.FindProperty("OomReports"), @@ -189,7 +190,7 @@ public override void OnInspectorGUI() } } -#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES +#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN EditorGUILayout.PropertyField( serializedObject.FindProperty("AddUnityLogToReport"), new GUIContent(BacktraceConfigurationLabels.LABEL_ADD_UNITY_LOG)); diff --git a/Editor/BacktraceDatabaseConfigurationEditor.cs b/Editor/BacktraceDatabaseConfigurationEditor.cs index 2bd50846..3688b10b 100644 --- a/Editor/BacktraceDatabaseConfigurationEditor.cs +++ b/Editor/BacktraceDatabaseConfigurationEditor.cs @@ -20,7 +20,7 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("Please insert valid Backtrace database path!", MessageType.Error); } -#if UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES +#if UNITY_STANDALONE_WIN settings.MinidumpType = (MiniDumpType)EditorGUILayout.EnumFlagsField(BacktraceConfigurationLabels.LABEL_MINIDUMP_SUPPORT, settings.MinidumpType); #else settings.MinidumpType = MiniDumpType.None; diff --git a/Runtime/Model/BacktraceConfiguration.cs b/Runtime/Model/BacktraceConfiguration.cs index 34e8dbb5..dbe10321 100644 --- a/Runtime/Model/BacktraceConfiguration.cs +++ b/Runtime/Model/BacktraceConfiguration.cs @@ -139,11 +139,13 @@ public class BacktraceConfiguration : ScriptableObject #endif public bool CaptureNativeCrashes = true; +#if !UNITY_GAMECORE_XBOXSERIES /// /// Handle ANR events - Application not responding /// [Tooltip("Capture ANR events - Application not responding")] public bool HandleANR = true; +#endif /// /// Anr watchdog timeout in ms. Time needed to detect an ANR event diff --git a/Runtime/Model/Database/BacktraceDatabaseSettings.cs b/Runtime/Model/Database/BacktraceDatabaseSettings.cs index 3ff966ef..bd050166 100644 --- a/Runtime/Model/Database/BacktraceDatabaseSettings.cs +++ b/Runtime/Model/Database/BacktraceDatabaseSettings.cs @@ -114,7 +114,7 @@ public bool AddUnityLogToReport { get { -#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES +#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN return _configuration.AddUnityLogToReport; #else return false; @@ -135,7 +135,7 @@ public MiniDumpType MinidumpType get { -#if UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES +#if UNITY_STANDALONE_WIN return _configuration.MinidumpType; #else return MiniDumpType.None; diff --git a/Runtime/Native/XBOX/NativeClient.cs b/Runtime/Native/XBOX/NativeClient.cs index efca92a8..cbeadf7e 100644 --- a/Runtime/Native/XBOX/NativeClient.cs +++ b/Runtime/Native/XBOX/NativeClient.cs @@ -19,28 +19,28 @@ namespace Backtrace.Unity.Runtime.Native.XBOX internal class NativeClient : NativeClientBase, INativeClient { - [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + [DllImport("backtrace_native_xbox_mt.dll")] private static extern bool BacktraceCrash(); - [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + [DllImport("backtrace_native_xbox_mt.dll")] private static extern bool BacktraceAddAttribute( [MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] string value ); - [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + [DllImport("backtrace_native_xbox_mt.dll")] private static extern bool BacktraceAddFile( [MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] string path ); - [DllImport("breakpad_xbox_simplified_abi_mt.dll")] + [DllImport("backtrace_native_xbox_mt.dll")] private static extern bool BacktraceSetUrl( [MarshalAs(UnmanagedType.LPWStr)] string url ); - [DllImport("breakpad_xbox_simplified_abi_mt.dll")] - private static extern bool BacktraceInitializeBreakpad(); + [DllImport("backtrace_native_xbox_mt.dll")] + private static extern bool BacktraceNativeInitialize(); /// /// Determine if the XBOX integration should be enabled @@ -60,13 +60,36 @@ public NativeClient(BacktraceConfiguration configuration, BacktraceBreadcrumbs b } AddScopedAttributes(clientAttributes); HandleNativeCrashes(clientAttributes, attachments); - if (!configuration.ReportFilterType.HasFlag(ReportFilterType.Hang)) + } + + public void GetAttributes(IDictionary attributes) + { + } + + public void HandleAnr() + { + } + + public bool OnOOM() + { + return false; + } + + public void SetAttribute(string key, string value) + { + if (string.IsNullOrEmpty(key)) { - HandleAnr(); + return; } + // avoid null reference in crashpad source code + if (value == null) + { + value = string.Empty; + } + BacktraceAddAttribute(key, value); } - internal void AddScopedAttributes(IDictionary attributes) + private void AddScopedAttributes(IDictionary attributes) { foreach (var attribute in attributes) { @@ -96,40 +119,13 @@ private void HandleNativeCrashes(IDictionary clientAttributes, I BacktraceAddFile(name, attachment); } - CaptureNativeCrashes = BacktraceInitializeBreakpad(); + CaptureNativeCrashes = BacktraceNativeInitialize(); if (!CaptureNativeCrashes) { - Debug.LogWarning("Backtrace native integration status: Cannot initialize the Breakpad client"); - return; - } - } - - public void GetAttributes(IDictionary attributes) - { - } - - public void HandleAnr() - { - } - - public bool OnOOM() - { - return false; - } - - public void SetAttribute(string key, string value) - { - if (string.IsNullOrEmpty(key)) - { + Debug.LogWarning("Backtrace native integration status: Cannot initialize the Native Crash Reporting client"); return; } - // avoid null reference in crashpad source code - if (value == null) - { - value = string.Empty; - } - BacktraceAddAttribute(key, value); } } } From ca6d004d47e86c69b0dc112f533fae490521cb1e Mon Sep 17 00:00:00 2001 From: kdysput Date: Tue, 18 Apr 2023 16:44:18 +0200 Subject: [PATCH 4/6] Catch possible exceptions throwed by the native client --- Runtime/Native/NativeClientFactory.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Runtime/Native/NativeClientFactory.cs b/Runtime/Native/NativeClientFactory.cs index ec226d3e..bc59b047 100644 --- a/Runtime/Native/NativeClientFactory.cs +++ b/Runtime/Native/NativeClientFactory.cs @@ -1,6 +1,8 @@ using Backtrace.Unity.Model; using Backtrace.Unity.Model.Breadcrumbs; +using System; using System.Collections.Generic; +using UnityEngine; namespace Backtrace.Unity.Runtime.Native { @@ -8,8 +10,10 @@ internal static class NativeClientFactory { internal static INativeClient CreateNativeClient(BacktraceConfiguration configuration, string gameObjectName, BacktraceBreadcrumbs breadcrumbs, IDictionary attributes, ICollection attachments) { + try + { #if UNITY_EDITOR - return null; + return null; #elif UNITY_GAMECORE_XBOXSERIES return new XBOX.NativeClient(configuration, breadcrumbs, attributes, attachments); #elif UNITY_STANDALONE_WIN @@ -21,6 +25,12 @@ internal static INativeClient CreateNativeClient(BacktraceConfiguration configur #else return null; #endif + } + catch (Exception e) + { + Debug.LogWarning(string.Format("Cannot startup the native client. Reason: {0}", e.Message)); + return null; + } } } } From fe8998323b392740760982c37a18edd518f7e690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Zakrzewski?= Date: Tue, 18 Apr 2023 16:46:11 +0200 Subject: [PATCH 5/6] Update the changelog. --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1188644c..b0b0ead9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Backtrace Unity Release Notes +## Version 3.8.0 + +New functionality +- Add support for XBox native crashes. + ## Version 3.7.9 Bugfixes From 95ff53971ec1ddfb032c3171ade7590d0bdbafbe Mon Sep 17 00:00:00 2001 From: kdysput Date: Tue, 18 Apr 2023 16:51:11 +0200 Subject: [PATCH 6/6] Version 3.8.0: Version update --- Runtime/BacktraceClient.cs | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/BacktraceClient.cs b/Runtime/BacktraceClient.cs index f8cb88d5..f035f33c 100644 --- a/Runtime/BacktraceClient.cs +++ b/Runtime/BacktraceClient.cs @@ -24,7 +24,7 @@ namespace Backtrace.Unity /// public class BacktraceClient : MonoBehaviour, IBacktraceClient { - public const string VERSION = "3.7.9"; + public const string VERSION = "3.8.0"; internal const string DefaultBacktraceGameObjectName = "BacktraceClient"; public BacktraceConfiguration Configuration; diff --git a/package.json b/package.json index 4e3477cf..daa2e031 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "io.backtrace.unity", "displayName": "Backtrace", - "version": "3.7.9", + "version": "3.8.0", "unity": "2017.1", "description": "Backtrace's integration with Unity games allows customers to capture and report handled and unhandled Unity exceptions to their Backtrace instance, instantly offering the ability to prioritize and debug software errors.", "keywords": [