Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Texture2D, SentryEvent, Texture2D?>)` callback that provides the captured screenshot as a
`Texture2D` before JPEG compression. ([#2428](https://github.com/getsentry/sentry-unity/pull/2428))
This enables:
Expand Down
11 changes: 11 additions & 0 deletions src/Sentry.Unity.Native/SentryNativeBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -48,6 +49,12 @@ 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)
Expand Down Expand Up @@ -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);

Expand All @@ -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))]
Expand Down
Loading