From 28f6876e44222670492fde9308b6df007b0cf5d0 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 13 Feb 2026 12:08:04 +0100 Subject: [PATCH 1/4] Acutally use the analyzer --- Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/Directory.Build.props b/Directory.Build.props index bae8e87f0..e4db6d4cd 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -40,6 +40,7 @@ + From 3881419af60e4d50cb47ee9f2544b924f66cf44c Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Fri, 13 Feb 2026 17:33:16 +0100 Subject: [PATCH 2/4] Exclude 'editor' --- Directory.Build.props | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Directory.Build.props b/Directory.Build.props index e4db6d4cd..f292f011d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -40,6 +40,9 @@ + + + From bdcdadf9d324e2f05b00e7ce576ab936587396cf Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 16 Feb 2026 12:12:51 +0100 Subject: [PATCH 3/4] Cleanup CacheDirectoryPath vs DatabasePath --- src/Sentry.Unity.Native/SentryNative.cs | 6 ++-- src/Sentry.Unity.Native/SentryNativeBridge.cs | 29 +++++++++---------- src/Sentry.Unity.Native/SentryNativeSwitch.cs | 4 +++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index df29f170e..4dd0c8459 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -70,17 +70,17 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf // Note: we must actually call the function now and on every other call use the value we get here. // Additionally, we cannot call this multiple times for the same directory, because the result changes // on subsequent runs. Therefore, we cache the value during the whole runtime of the application. - var cacheDirectory = SentryNativeBridge.GetCacheDirectory(options); + var databasePath = SentryNativeBridge.GetDatabasePath(options); var crashedLastRun = false; // In the event the SDK is re-initialized with a different path on disk, we need to track which ones were already read // Similarly we need to cache the value of each call since a subsequent call would return a different value // as the file used on disk to mark it as crashed is deleted after we read it. lock (PerDirectoryCrashInfo) { - if (!PerDirectoryCrashInfo.TryGetValue(cacheDirectory, out crashedLastRun)) + if (!PerDirectoryCrashInfo.TryGetValue(databasePath, out crashedLastRun)) { crashedLastRun = SentryNativeBridge.HandleCrashedLastRun(options); - PerDirectoryCrashInfo.Add(cacheDirectory, crashedLastRun); + PerDirectoryCrashInfo.Add(databasePath, crashedLastRun); Logger? .LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun); diff --git a/src/Sentry.Unity.Native/SentryNativeBridge.cs b/src/Sentry.Unity.Native/SentryNativeBridge.cs index f3d018e33..81ac5c721 100644 --- a/src/Sentry.Unity.Native/SentryNativeBridge.cs +++ b/src/Sentry.Unity.Native/SentryNativeBridge.cs @@ -2,6 +2,7 @@ using System.IO; using System.Runtime.InteropServices; using Sentry.Extensibility; +using Sentry.Unity.Integrations; using UnityEngine; using AOT; @@ -68,21 +69,21 @@ is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer sentry_options_set_attach_screenshot(cOptions, options.AttachScreenshot ? 1 : 0); } - var dir = GetCacheDirectory(options); + var databasePath = GetDatabasePath(options); #if SENTRY_NATIVE_SWITCH - Logger?.LogDebug("Setting CacheDirectoryPath: {0}", dir); - sentry_options_set_database_path(cOptions, dir); + Logger?.LogDebug("Setting DatabasePath: {0}", databasePath); + sentry_options_set_database_path(cOptions, databasePath); #else // Note: don't use RuntimeInformation.IsOSPlatform - it will report windows on WSL. if (IsWindows) { - Logger?.LogDebug("Setting CacheDirectoryPath on Windows: {0}", dir); - sentry_options_set_database_pathw(cOptions, dir); + Logger?.LogDebug("Setting DatabasePath on Windows: {0}", databasePath); + sentry_options_set_database_pathw(cOptions, databasePath); } else { - Logger?.LogDebug("Setting CacheDirectoryPath: {0}", dir); - sentry_options_set_database_path(cOptions, dir); + Logger?.LogDebug("Setting DatabasePath: {0}", databasePath); + sentry_options_set_database_path(cOptions, databasePath); } #endif @@ -111,17 +112,15 @@ internal static bool HandleCrashedLastRun(SentryUnityOptions options) return result; } - internal static string GetCacheDirectory(SentryUnityOptions options) + internal static string GetDatabasePath(SentryUnityOptions options, IApplication? application = null) { - if (options.CacheDirectoryPath is null) + if (options.CacheDirectoryPath is not null) { - // same as the default of sentry-native - return Path.Combine(Directory.GetCurrentDirectory(), ".sentry-native"); - } - else - { - return Path.Combine(options.CacheDirectoryPath, "SentryNative"); + return Path.Combine(options.CacheDirectoryPath, ".sentry-native"); } + + application ??= ApplicationAdapter.Instance; + return Path.Combine(application.PersistentDataPath, ".sentry-native"); } internal static void ReinstallBackend() => sentry_reinstall_backend(); diff --git a/src/Sentry.Unity.Native/SentryNativeSwitch.cs b/src/Sentry.Unity.Native/SentryNativeSwitch.cs index 0f18277b2..6fab13909 100644 --- a/src/Sentry.Unity.Native/SentryNativeSwitch.cs +++ b/src/Sentry.Unity.Native/SentryNativeSwitch.cs @@ -89,6 +89,10 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf return; } + // Setting CacheDirectoryPath here so that GetDatabasePath() finds it in step 1 of its + // cascading resolution. On Switch, DisableFileWrite is true, which prevents the .NET + // CachingTransport from using this path for offline caching — it only serves as the + // base for the native database path. Logger?.LogDebug("Setting native cache directory: {0}", cachePath); options.CacheDirectoryPath = cachePath; From a108c0be43ffdcc25473628844f6c182f72e654e Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 16 Feb 2026 16:21:32 +0100 Subject: [PATCH 4/4] Check file writing early --- src/Sentry.Unity.Native/SentryNative.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index df29f170e..8c00c79e1 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -37,6 +37,12 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf return; } + if (options.DisableFileWrite) + { + Logger?.LogWarning("Native support disabled because it requires file writing."); + return; + } + try { if (!SentryNativeBridge.Init(options))