Skip to content

Commit be020a5

Browse files
authored
feat: Screenshots on native Windows events (#2434)
1 parent 0d5c87a commit be020a5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
### Features
1313

14+
- 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))
1415
- Added `SetBeforeSendScreenshot(Func<Texture2D, SentryEvent, Texture2D?>)` callback that provides the captured screenshot as a
1516
`Texture2D` before JPEG compression. ([#2428](https://github.com/getsentry/sentry-unity/pull/2428))
1617
This enables:

src/Sentry.Unity.Native/SentryNativeBridge.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal static class SentryNativeBridge
1717
public static bool Init(SentryUnityOptions options)
1818
{
1919
_isLinux = Application.platform is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer;
20+
_isWindows = Application.platform is RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer;
2021

2122
var cOptions = sentry_options_new();
2223

@@ -48,9 +49,15 @@ public static bool Init(SentryUnityOptions options)
4849
options.DiagnosticLogger?.LogDebug("Disabling native auto session tracking");
4950
sentry_options_set_auto_session_tracking(cOptions, 0);
5051

52+
if (_isWindows)
53+
{
54+
options.DiagnosticLogger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot);
55+
sentry_options_set_attach_screenshot(cOptions, options.AttachScreenshot ? 1 : 0);
56+
}
57+
5158
var dir = GetCacheDirectory(options);
5259
// Note: don't use RuntimeInformation.IsOSPlatform - it will report windows on WSL.
53-
if (ApplicationAdapter.Instance.Platform is RuntimePlatform.WindowsPlayer)
60+
if (_isWindows)
5461
{
5562
options.DiagnosticLogger?.LogDebug("Setting CacheDirectoryPath on Windows: {0}", dir);
5663
sentry_options_set_database_pathw(cOptions, dir);
@@ -131,6 +138,9 @@ internal static string GetCacheDirectory(SentryUnityOptions options)
131138
[DllImport("sentry")]
132139
private static extern void sentry_options_set_auto_session_tracking(IntPtr options, int debug);
133140

141+
[DllImport("sentry")]
142+
private static extern void sentry_options_set_attach_screenshot(IntPtr options, int attachScreenshot);
143+
134144
[UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true)]
135145
private delegate void sentry_logger_function_t(int level, IntPtr message, IntPtr argsAddress, IntPtr userData);
136146

@@ -140,6 +150,7 @@ internal static string GetCacheDirectory(SentryUnityOptions options)
140150
// The logger we should forward native messages to. This is referenced by nativeLog() which in turn for.
141151
private static IDiagnosticLogger? _logger;
142152
private static bool _isLinux = false;
153+
private static bool _isWindows = false;
143154

144155
// This method is called from the C library and forwards incoming messages to the currently set _logger.
145156
[MonoPInvokeCallback(typeof(sentry_logger_function_t))]

0 commit comments

Comments
 (0)