-
-
Notifications
You must be signed in to change notification settings - Fork 59
feat: improve Xbox native support #2617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eab7187
6fc7e0e
9beb98b
3acc2d9
ff07320
f3c37dd
c294071
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This excludes the assembly from being included in Xbox builds. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,4 +46,23 @@ | |
| /> | ||
| </Target> | ||
|
|
||
| <!-- Build Xbox version after the Switch build --> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pattern has already been established above. |
||
| <Target Name="BuildXboxAssembly" AfterTargets="BuildSwitchAssembly"> | ||
| <Message Importance="High" Text="Building Xbox-specific native assembly." /> | ||
|
|
||
| <Csc | ||
| Sources="@(Compile)" | ||
| References="@(ReferencePath)" | ||
| OutputAssembly="$(OutDir)Sentry.Unity.Native.Xbox.dll" | ||
| DefineConstants="$(DefineConstants);SENTRY_NATIVE_XBOX" | ||
| TargetType="library" | ||
| EmitDebugInformation="true" | ||
| DebugType="portable" | ||
| Nullable="$(Nullable)" | ||
| LangVersion="$(LangVersion)" | ||
| TreatWarningsAsErrors="$(TreatWarningsAsErrors)" | ||
| WarningLevel="$(WarningLevel)" | ||
| /> | ||
| </Target> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,9 @@ public static bool Init(SentryUnityOptions options) | |
| UseLibC = Application.platform | ||
| is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer | ||
| or RuntimePlatform.PS5 or RuntimePlatform.Switch; | ||
| IsWindows = Application.platform is RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer; | ||
| IsWindows = Application.platform | ||
| is RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer | ||
| or RuntimePlatform.GameCoreXboxSeries or RuntimePlatform.GameCoreXboxOne; | ||
|
Comment on lines
+35
to
+36
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used to determine how the SDK handled and passes paths to |
||
|
|
||
| var cOptions = sentry_options_new(); | ||
|
|
||
|
|
@@ -69,6 +71,10 @@ is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer | |
| sentry_options_set_attach_screenshot(cOptions, options.AttachScreenshot ? 1 : 0); | ||
| } | ||
|
|
||
| #if SENTRY_NATIVE_XBOX | ||
| SentryNativeXbox.ResolveStoragePath(options, Logger); | ||
| #endif | ||
|
|
||
| var databasePath = GetDatabasePath(options); | ||
| #if SENTRY_NATIVE_SWITCH | ||
| Logger?.LogDebug("Setting DatabasePath: {0}", databasePath); | ||
|
|
@@ -119,6 +125,8 @@ internal static string GetDatabasePath(SentryUnityOptions options, IApplication? | |
| return Path.Combine(options.CacheDirectoryPath, ".sentry-native"); | ||
| } | ||
|
|
||
| // This is a fallback attempting to provide native crash support in case of CacheDirectoryPath not being set. | ||
| // Xbox and Switch rely on their own mechanisms to resolve storage, see SentryNativeXbox and SentryNativeSwitch. | ||
| application ??= ApplicationAdapter.Instance; | ||
| return Path.Combine(application.PersistentDataPath, ".sentry-native"); | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #if SENTRY_NATIVE_XBOX | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using Sentry.Extensibility; | ||
|
|
||
| namespace Sentry.Unity.Native; | ||
|
|
||
| /// <summary> | ||
| /// Xbox-specific helpers for Sentry native support. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// On Xbox, <c>Application.persistentDataPath</c> returns an empty string for packaged (installed) builds. | ||
| /// The writable storage must be resolved via the Xbox Persistent Local Storage (PLS) API, which requires | ||
| /// <c>PersistentLocalStorage</c> to be configured in the game's <c>MicrosoftGame.config</c>. | ||
| /// </remarks> | ||
| internal static class SentryNativeXbox | ||
| { | ||
| [DllImport("sentry")] | ||
| private static extern IntPtr sentry_xbox_utils_get_pls_path(); | ||
|
|
||
| /// <summary> | ||
| /// Resolves the Xbox Persistent Local Storage path and sets <see cref="SentryOptions.CacheDirectoryPath"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Called from <see cref="SentryNative.Configure"/> before native SDK initialization. | ||
| /// If PLS is not available (e.g. not configured in MicrosoftGame.config), the cache directory | ||
| /// is left unset. The SDK will operate without offline caching, session persistence, or native crash reporting. | ||
| /// </remarks> | ||
| internal static void ResolveStoragePath(SentryUnityOptions options, IDiagnosticLogger? logger) | ||
| { | ||
| if (!string.IsNullOrEmpty(options.CacheDirectoryPath)) | ||
| { | ||
| logger?.LogWarning("The 'CacheDirectoryPath' has already been set by the user. " + | ||
| "Storage path resolution will be skipped."); | ||
| return; | ||
| } | ||
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| string? plsPath = null; | ||
| try | ||
| { | ||
| var plsPathPtr = sentry_xbox_utils_get_pls_path(); | ||
| plsPath = Marshal.PtrToStringAnsi(plsPathPtr); | ||
| } | ||
| catch (EntryPointNotFoundException) | ||
| { | ||
| logger?.LogWarning("Failed to find 'sentry_xbox_utils_get_pls_path' in sentry.dll."); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(plsPath)) | ||
| { | ||
| logger?.LogDebug("Setting Persistent Local Storage as cache directory path: '{0}'", plsPath); | ||
| options.CacheDirectoryPath = plsPath; | ||
| } | ||
| else | ||
| { | ||
| logger?.LogWarning("Failed to retrieve Xbox Persistent Local Storage path. " + | ||
| "Ensure 'PersistentLocalStorage' is configured in MicrosoftGame.config. " + | ||
| "Offline caching, session persistence, and native crash support will be disabled."); | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes this assembly for Xbox builds.