From 4c8da62b48ee47b52314d6c893353c36b68fdabe Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 24 Nov 2025 11:57:35 +0100 Subject: [PATCH 1/4] Propagating the option --- src/Sentry.Unity.Native/SentryNativeBridge.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Sentry.Unity.Native/SentryNativeBridge.cs b/src/Sentry.Unity.Native/SentryNativeBridge.cs index 644c52018..69cbc7415 100644 --- a/src/Sentry.Unity.Native/SentryNativeBridge.cs +++ b/src/Sentry.Unity.Native/SentryNativeBridge.cs @@ -48,6 +48,9 @@ public static bool Init(SentryUnityOptions options) options.DiagnosticLogger?.LogDebug("Disabling native auto session tracking"); sentry_options_set_auto_session_tracking(cOptions, 0); + options.DiagnosticLogger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot); + sentry_options_set_attach_screenshot(cOptions, options.AttachScreenshot ? 1 : 0); + var dir = GetCacheDirectory(options); // Note: don't use RuntimeInformation.IsOSPlatform - it will report windows on WSL. if (ApplicationAdapter.Instance.Platform is RuntimePlatform.WindowsPlayer) @@ -131,6 +134,9 @@ internal static string GetCacheDirectory(SentryUnityOptions options) [DllImport("sentry")] private static extern void sentry_options_set_auto_session_tracking(IntPtr options, int debug); + [DllImport("sentry")] + private static extern void sentry_options_set_attach_screenshot(IntPtr options, int attachScreenshot); + [UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true)] private delegate void sentry_logger_function_t(int level, IntPtr message, IntPtr argsAddress, IntPtr userData); From ab0bf928cb2be15901aaba9bcf120edfdb4b3015 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 24 Nov 2025 12:00:54 +0100 Subject: [PATCH 2/4] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ca810d4e..63df0e2da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Features +- On Windows, and with screenshot capture enabled, the SDK will now also capture and attach a screenshot to native crashes ([#2434](https://github.com/getsentry/sentry-unity/pull/2434)) - Added `SetBeforeSendScreenshot(Func)` callback that provides the captured screenshot as a `Texture2D` before JPEG compression. ([#2428](https://github.com/getsentry/sentry-unity/pull/2428)) This enables: From 2bc084995ad1c5a613cafe14fa5ac0a6db5fb5ad Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 24 Nov 2025 18:08:53 +0100 Subject: [PATCH 3/4] Windows exclusive --- src/Sentry.Unity.Native/SentryNativeBridge.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Sentry.Unity.Native/SentryNativeBridge.cs b/src/Sentry.Unity.Native/SentryNativeBridge.cs index 69cbc7415..cd37513d0 100644 --- a/src/Sentry.Unity.Native/SentryNativeBridge.cs +++ b/src/Sentry.Unity.Native/SentryNativeBridge.cs @@ -17,6 +17,7 @@ internal static class SentryNativeBridge public static bool Init(SentryUnityOptions options) { _isLinux = Application.platform is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer; + _isWindows = Application.platform is RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer; var cOptions = sentry_options_new(); @@ -48,8 +49,11 @@ public static bool Init(SentryUnityOptions options) options.DiagnosticLogger?.LogDebug("Disabling native auto session tracking"); sentry_options_set_auto_session_tracking(cOptions, 0); - options.DiagnosticLogger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot); - sentry_options_set_attach_screenshot(cOptions, options.AttachScreenshot ? 1 : 0); + if (_isWindows) + { + options.DiagnosticLogger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot); + sentry_options_set_attach_screenshot(cOptions, options.AttachScreenshot ? 1 : 0); + } var dir = GetCacheDirectory(options); // Note: don't use RuntimeInformation.IsOSPlatform - it will report windows on WSL. @@ -146,6 +150,7 @@ internal static string GetCacheDirectory(SentryUnityOptions options) // The logger we should forward native messages to. This is referenced by nativeLog() which in turn for. private static IDiagnosticLogger? _logger; private static bool _isLinux = false; + private static bool _isWindows = false; // This method is called from the C library and forwards incoming messages to the currently set _logger. [MonoPInvokeCallback(typeof(sentry_logger_function_t))] From 2a907383629c89c6981a3f883a5821dadb1bec54 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 27 Nov 2025 11:59:22 +0100 Subject: [PATCH 4/4] Check --- src/Sentry.Unity.Native/SentryNativeBridge.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity.Native/SentryNativeBridge.cs b/src/Sentry.Unity.Native/SentryNativeBridge.cs index cd37513d0..b73f179b4 100644 --- a/src/Sentry.Unity.Native/SentryNativeBridge.cs +++ b/src/Sentry.Unity.Native/SentryNativeBridge.cs @@ -57,7 +57,7 @@ public static bool Init(SentryUnityOptions options) var dir = GetCacheDirectory(options); // Note: don't use RuntimeInformation.IsOSPlatform - it will report windows on WSL. - if (ApplicationAdapter.Instance.Platform is RuntimePlatform.WindowsPlayer) + if (_isWindows) { options.DiagnosticLogger?.LogDebug("Setting CacheDirectoryPath on Windows: {0}", dir); sentry_options_set_database_pathw(cOptions, dir);