From 5a843a5a55299c11055f2ae1f3ae3df98d849958 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 28 Jul 2026 18:24:06 +0200 Subject: [PATCH] don't log while crashing --- 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 0919895b5..ced5a9a56 100644 --- a/src/Sentry.Unity.Native/SentryNativeBridge.cs +++ b/src/Sentry.Unity.Native/SentryNativeBridge.cs @@ -115,6 +115,9 @@ is RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer { Logger?.LogDebug("Setting the native logger"); sentry_options_set_logger(cOptions, new sentry_logger_function_t(nativeLog), IntPtr.Zero); + + // Crash handlers must not invoke Unity's managed logger from the faulting thread. + sentry_options_set_logger_enabled_when_crashed(cOptions, 0); } else { @@ -214,6 +217,9 @@ internal static string GetDatabasePath(SentryUnityOptions options, IApplication? [DllImport(SentryLib)] private static extern void sentry_options_set_logger(IntPtr options, sentry_logger_function_t logger, IntPtr userData); + [DllImport(SentryLib)] + private static extern void sentry_options_set_logger_enabled_when_crashed(IntPtr options, int enabled); + // This method is called from the C library and forwards incoming messages to the currently set _logger. [MonoPInvokeCallback(typeof(sentry_logger_function_t))] private static void nativeLog(int cLevel, IntPtr format, IntPtr args, IntPtr userData)