Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions Editor/BacktraceConfigurationEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion Runtime/BacktraceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Backtrace.Unity
/// </summary>
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;

Expand Down
6 changes: 4 additions & 2 deletions Runtime/Model/BacktraceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,27 @@ 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
/// <summary>
/// Capture native NDK Crashes.
/// </summary>
[Tooltip("Capture native NDK Crashes (ANDROID API 21+)")]
#elif UNITY_IOS || UNITY_STANDALONE_WIN
#elif UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES
/// <summary>
/// Capture native crashes.
/// </summary>
[Tooltip("Capture native Crashes")]
#endif

public bool CaptureNativeCrashes = true;
#if !UNITY_GAMECORE_XBOXSERIES
/// <summary>
/// Handle ANR events - Application not responding
/// </summary>
[Tooltip("Capture ANR events - Application not responding")]
public bool HandleANR = true;
#endif

/// <summary>
/// Anr watchdog timeout in ms. Time needed to detect an ANR event
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Native/Base/NativeClientBase.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
14 changes: 13 additions & 1 deletion Runtime/Native/NativeClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
using Backtrace.Unity.Model;
using Backtrace.Unity.Model.Breadcrumbs;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Backtrace.Unity.Runtime.Native
{
internal static class NativeClientFactory
{
internal static INativeClient CreateNativeClient(BacktraceConfiguration configuration, string gameObjectName, BacktraceBreadcrumbs breadcrumbs, IDictionary<string, string> attributes, ICollection<string> 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
Expand All @@ -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;
}
}
}
}
8 changes: 8 additions & 0 deletions Runtime/Native/XBOX.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions Runtime/Native/XBOX/NativeClient.cs
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to start every method in "Backtrace" library with prefix "Backtrace"? I think it is obvious enough if we call it "Crash"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DLL exposes undecorated symbols, C-style. It's idiomatic to namespace them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but the dll is alerady backtrace dll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the issue. C does not have namespaces. If we have a method Initialize() in our DLL, and another DLL exposes the same method, they will clash.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you call the dll directly based on the dll name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's a hard requirement for you, I can do it. But IMO it's better to offer one generic library that we could reuse in other projects.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's still can be generic, right? We can share the library with a note it's an abi_mt library. We don't need to show in our code we use breakpad or this is the "simplify" the library. If we switch to other crash reporter for any reason someone will have more manual work to do. Can we just rename it to backtrace-xbox?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm of two minds here. We actually offer multiple versions of Breakpad because some customers use mt/md libraries.


[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();

/// <summary>
/// Determine if the XBOX integration should be enabled
/// </summary>
private bool _enabled =
#if UNITY_GAMECORE_XBOXSERIES && !UNITY_EDITOR
true;
#else
false;
#endif

public NativeClient(BacktraceConfiguration configuration, BacktraceBreadcrumbs breadcrumbs, IDictionary<string, string> clientAttributes, IEnumerable<string> attachments) : base(configuration, breadcrumbs)
{
if (!_enabled)
{
return;
}
AddScopedAttributes(clientAttributes);
HandleNativeCrashes(clientAttributes, attachments);
}

public void GetAttributes(IDictionary<string, string> 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<string, string> attributes)
{
foreach (var attribute in attributes)
{
if (string.IsNullOrEmpty(attribute.Key) || attribute.Value == null)
{
continue;
}

BacktraceAddAttribute(attribute.Key, attribute.Value);
}
}

private void HandleNativeCrashes(IDictionary<string, string> clientAttributes, IEnumerable<string> 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
11 changes: 11 additions & 0 deletions Runtime/Native/XBOX/NativeClient.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down