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 diff --git a/Editor/BacktraceConfigurationEditor.cs b/Editor/BacktraceConfigurationEditor.cs index 1b8d4670..153425cc 100644 --- a/Editor/BacktraceConfigurationEditor.cs +++ b/Editor/BacktraceConfigurationEditor.cs @@ -137,7 +137,7 @@ public override void OnInspectorGUI() #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, @@ -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"), 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/Runtime/Model/BacktraceConfiguration.cs b/Runtime/Model/BacktraceConfiguration.cs index 2053af50..dbe10321 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. /// @@ -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/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..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,12 @@ 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 return new Windows.NativeClient(configuration, breadcrumbs, attributes, attachments); #elif UNITY_ANDROID @@ -19,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; + } } } } 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..cbeadf7e --- /dev/null +++ b/Runtime/Native/XBOX/NativeClient.cs @@ -0,0 +1,132 @@ +#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("backtrace_native_xbox_mt.dll")] + private static extern bool BacktraceCrash(); + + [DllImport("backtrace_native_xbox_mt.dll")] + private static extern bool BacktraceAddAttribute( + [MarshalAs(UnmanagedType.LPWStr)] string name, + [MarshalAs(UnmanagedType.LPWStr)] string value + ); + + [DllImport("backtrace_native_xbox_mt.dll")] + private static extern bool BacktraceAddFile( + [MarshalAs(UnmanagedType.LPWStr)] string name, + [MarshalAs(UnmanagedType.LPWStr)] string path + ); + + [DllImport("backtrace_native_xbox_mt.dll")] + private static extern bool BacktraceSetUrl( + [MarshalAs(UnmanagedType.LPWStr)] string url + ); + + [DllImport("backtrace_native_xbox_mt.dll")] + private static extern bool BacktraceNativeInitialize(); + + /// + /// 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); + } + + public void GetAttributes(IDictionary attributes) + { + } + + public void HandleAnr() + { + } + + public bool OnOOM() + { + return false; + } + + 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); + } + + private void AddScopedAttributes(IDictionary attributes) + { + foreach (var attribute in attributes) + { + if (string.IsNullOrEmpty(attribute.Key) || 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(); + BacktraceSetUrl(minidumpUrl); + + foreach (var attachment in attachments) + { + var name = Path.GetFileName(attachment); + BacktraceAddFile(name, attachment); + } + + CaptureNativeCrashes = BacktraceNativeInitialize(); + + if (!CaptureNativeCrashes) + { + Debug.LogWarning("Backtrace native integration status: Cannot initialize the Native Crash Reporting client"); + return; + } + } + } +} +#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: 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": [