diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f50f297e..72e8a57a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,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: diff --git a/src/Sentry.Unity.Native/SentryNativeBridge.cs b/src/Sentry.Unity.Native/SentryNativeBridge.cs index 644c52018..b73f179b4 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,9 +49,15 @@ public static bool Init(SentryUnityOptions options) options.DiagnosticLogger?.LogDebug("Disabling native auto session tracking"); sentry_options_set_auto_session_tracking(cOptions, 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. - 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); @@ -131,6 +138,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); @@ -140,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))]