Skip to content

Commit e3ec70d

Browse files
KrzaQPaweł Zakrzewskikonraddysput
authored
Add XBOX support. (#183)
* Add XBOX support. * Respond to comments from Konrad * Respond to comments, should be all ok by now. * Catch possible exceptions throwed by the native client * Update the changelog. * Version 3.8.0: Version update --------- Co-authored-by: Paweł Zakrzewski <pzakrzewski@backtrace.io> Co-authored-by: kdysput <konrad.dysput@gmail.com>
1 parent 4526b88 commit e3ec70d

File tree

10 files changed

+179
-8
lines changed

10 files changed

+179
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Backtrace Unity Release Notes
22

3+
## Version 3.8.0
4+
5+
New functionality
6+
- Add support for XBox native crashes.
7+
38
## Version 3.7.9
49

510
Bugfixes

Editor/BacktraceConfigurationEditor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public override void OnInspectorGUI()
137137
#endif
138138

139139

140-
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN
140+
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES
141141
SerializedProperty captureNativeCrashes = serializedObject.FindProperty("CaptureNativeCrashes");
142142
EditorGUILayout.PropertyField(
143143
captureNativeCrashes,
@@ -148,10 +148,11 @@ public override void OnInspectorGUI()
148148
EditorGUILayout.HelpBox("You're using Backtrace-Unity integration with Unity 16b NDK support. Please contact Backtrace support for any additional help", MessageType.Warning);
149149
}
150150
#endif
151-
151+
#if !UNITY_GAMECORE_XBOXSERIES
152152
EditorGUILayout.PropertyField(
153153
serializedObject.FindProperty("HandleANR"),
154154
new GUIContent(BacktraceConfigurationLabels.LABEL_HANDLE_ANR));
155+
#endif
155156
#if UNITY_ANDROID || UNITY_IOS
156157
EditorGUILayout.PropertyField(
157158
serializedObject.FindProperty("OomReports"),

Runtime/BacktraceClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Backtrace.Unity
2424
/// </summary>
2525
public class BacktraceClient : MonoBehaviour, IBacktraceClient
2626
{
27-
public const string VERSION = "3.7.9";
27+
public const string VERSION = "3.8.0";
2828
internal const string DefaultBacktraceGameObjectName = "BacktraceClient";
2929
public BacktraceConfiguration Configuration;
3030

Runtime/Model/BacktraceConfiguration.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,27 @@ public class BacktraceConfiguration : ScriptableObject
125125
[Tooltip("Try to find game native crashes and send them on Game startup")]
126126
public bool SendUnhandledGameCrashesOnGameStartup = true;
127127

128-
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN
128+
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES
129129
#if UNITY_ANDROID
130130
/// <summary>
131131
/// Capture native NDK Crashes.
132132
/// </summary>
133133
[Tooltip("Capture native NDK Crashes (ANDROID API 21+)")]
134-
#elif UNITY_IOS || UNITY_STANDALONE_WIN
134+
#elif UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES
135135
/// <summary>
136136
/// Capture native crashes.
137137
/// </summary>
138138
[Tooltip("Capture native Crashes")]
139139
#endif
140140

141141
public bool CaptureNativeCrashes = true;
142+
#if !UNITY_GAMECORE_XBOXSERIES
142143
/// <summary>
143144
/// Handle ANR events - Application not responding
144145
/// </summary>
145146
[Tooltip("Capture ANR events - Application not responding")]
146147
public bool HandleANR = true;
148+
#endif
147149

148150
/// <summary>
149151
/// Anr watchdog timeout in ms. Time needed to detect an ANR event

Runtime/Native/Base/NativeClientBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN
1+
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES
22
using Backtrace.Unity.Model;
33
using Backtrace.Unity.Model.Breadcrumbs;
44
using Backtrace.Unity.Extensions;

Runtime/Native/NativeClientFactory.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
using Backtrace.Unity.Model;
22
using Backtrace.Unity.Model.Breadcrumbs;
3+
using System;
34
using System.Collections.Generic;
5+
using UnityEngine;
46

57
namespace Backtrace.Unity.Runtime.Native
68
{
79
internal static class NativeClientFactory
810
{
911
internal static INativeClient CreateNativeClient(BacktraceConfiguration configuration, string gameObjectName, BacktraceBreadcrumbs breadcrumbs, IDictionary<string, string> attributes, ICollection<string> attachments)
1012
{
13+
try
14+
{
1115
#if UNITY_EDITOR
12-
return null;
16+
return null;
17+
#elif UNITY_GAMECORE_XBOXSERIES
18+
return new XBOX.NativeClient(configuration, breadcrumbs, attributes, attachments);
1319
#elif UNITY_STANDALONE_WIN
1420
return new Windows.NativeClient(configuration, breadcrumbs, attributes, attachments);
1521
#elif UNITY_ANDROID
@@ -19,6 +25,12 @@ internal static INativeClient CreateNativeClient(BacktraceConfiguration configur
1925
#else
2026
return null;
2127
#endif
28+
}
29+
catch (Exception e)
30+
{
31+
Debug.LogWarning(string.Format("Cannot startup the native client. Reason: {0}", e.Message));
32+
return null;
33+
}
2234
}
2335
}
2436
}

Runtime/Native/XBOX.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#if UNITY_GAMECORE_XBOXSERIES
2+
using Backtrace.Unity.Interfaces;
3+
using Backtrace.Unity.Model;
4+
using Backtrace.Unity.Model.Breadcrumbs;
5+
using Backtrace.Unity.Runtime.Native.Base;
6+
using Backtrace.Unity.Types;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.IO;
10+
using System.Linq;
11+
using System.Runtime.InteropServices;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
using UnityEngine;
15+
16+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Backtrace.Unity.Tests.Runtime")]
17+
namespace Backtrace.Unity.Runtime.Native.XBOX
18+
{
19+
20+
internal class NativeClient : NativeClientBase, INativeClient
21+
{
22+
[DllImport("backtrace_native_xbox_mt.dll")]
23+
private static extern bool BacktraceCrash();
24+
25+
[DllImport("backtrace_native_xbox_mt.dll")]
26+
private static extern bool BacktraceAddAttribute(
27+
[MarshalAs(UnmanagedType.LPWStr)] string name,
28+
[MarshalAs(UnmanagedType.LPWStr)] string value
29+
);
30+
31+
[DllImport("backtrace_native_xbox_mt.dll")]
32+
private static extern bool BacktraceAddFile(
33+
[MarshalAs(UnmanagedType.LPWStr)] string name,
34+
[MarshalAs(UnmanagedType.LPWStr)] string path
35+
);
36+
37+
[DllImport("backtrace_native_xbox_mt.dll")]
38+
private static extern bool BacktraceSetUrl(
39+
[MarshalAs(UnmanagedType.LPWStr)] string url
40+
);
41+
42+
[DllImport("backtrace_native_xbox_mt.dll")]
43+
private static extern bool BacktraceNativeInitialize();
44+
45+
/// <summary>
46+
/// Determine if the XBOX integration should be enabled
47+
/// </summary>
48+
private bool _enabled =
49+
#if UNITY_GAMECORE_XBOXSERIES && !UNITY_EDITOR
50+
true;
51+
#else
52+
false;
53+
#endif
54+
55+
public NativeClient(BacktraceConfiguration configuration, BacktraceBreadcrumbs breadcrumbs, IDictionary<string, string> clientAttributes, IEnumerable<string> attachments) : base(configuration, breadcrumbs)
56+
{
57+
if (!_enabled)
58+
{
59+
return;
60+
}
61+
AddScopedAttributes(clientAttributes);
62+
HandleNativeCrashes(clientAttributes, attachments);
63+
}
64+
65+
public void GetAttributes(IDictionary<string, string> attributes)
66+
{
67+
}
68+
69+
public void HandleAnr()
70+
{
71+
}
72+
73+
public bool OnOOM()
74+
{
75+
return false;
76+
}
77+
78+
public void SetAttribute(string key, string value)
79+
{
80+
if (string.IsNullOrEmpty(key))
81+
{
82+
return;
83+
}
84+
// avoid null reference in crashpad source code
85+
if (value == null)
86+
{
87+
value = string.Empty;
88+
}
89+
BacktraceAddAttribute(key, value);
90+
}
91+
92+
private void AddScopedAttributes(IDictionary<string, string> attributes)
93+
{
94+
foreach (var attribute in attributes)
95+
{
96+
if (string.IsNullOrEmpty(attribute.Key) || attribute.Value == null)
97+
{
98+
continue;
99+
}
100+
101+
BacktraceAddAttribute(attribute.Key, attribute.Value);
102+
}
103+
}
104+
105+
private void HandleNativeCrashes(IDictionary<string, string> clientAttributes, IEnumerable<string> attachments)
106+
{
107+
var integrationDisabled = !_configuration.CaptureNativeCrashes || !_configuration.Enabled;
108+
if (integrationDisabled)
109+
{
110+
return;
111+
}
112+
113+
var minidumpUrl = new BacktraceCredentials(_configuration.GetValidServerUrl()).GetMinidumpSubmissionUrl().ToString();
114+
BacktraceSetUrl(minidumpUrl);
115+
116+
foreach (var attachment in attachments)
117+
{
118+
var name = Path.GetFileName(attachment);
119+
BacktraceAddFile(name, attachment);
120+
}
121+
122+
CaptureNativeCrashes = BacktraceNativeInitialize();
123+
124+
if (!CaptureNativeCrashes)
125+
{
126+
Debug.LogWarning("Backtrace native integration status: Cannot initialize the Native Crash Reporting client");
127+
return;
128+
}
129+
}
130+
}
131+
}
132+
#endif

Runtime/Native/XBOX/NativeClient.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "io.backtrace.unity",
33
"displayName": "Backtrace",
4-
"version": "3.7.9",
4+
"version": "3.8.0",
55
"unity": "2017.1",
66
"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.",
77
"keywords": [

0 commit comments

Comments
 (0)