Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only close the native SDKs if native support has been enabled #1897

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- The SDK no longer closes the underlying native SDK during the games shutdown if native support has not been enabled. This enables the SDK to support and capture errors in case of building the game as a library. ([#1897](https://github.com/getsentry/sentry-unity/pull/1897))
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

### Dependencies

- Bump .NET SDK from v4.12.1 to v4.13.0 ([#1879](https://github.com/getsentry/sentry-unity/pull/1879), [#1885](https://github.com/getsentry/sentry-unity/pull/1885))
Expand Down
4 changes: 2 additions & 2 deletions package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public static void Init()
{
// Closing down the native layer that are set up during build and self-initialize
#if SENTRY_NATIVE_COCOA
SentryNativeCocoa.Close(options.DiagnosticLogger);
SentryNativeCocoa.Close(options, sentryUnityInfo);
#elif SENTRY_NATIVE_ANDROID
SentryNativeAndroid.Close(options.DiagnosticLogger);
SentryNativeAndroid.Close(options, sentryUnityInfo);
#endif
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/Sentry.Unity.Android/SentryNativeAndroid.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using Sentry.Extensibility;
using Sentry.Unity.Integrations;
using UnityEngine;
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved
using UnityEngine.Analytics;

namespace Sentry.Unity.Android;
Expand Down Expand Up @@ -74,7 +76,7 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry
e, "Failed to reinstall backend. Captured native crashes will miss scope data and tag.");
}

options.NativeSupportCloseCallback = () => Close(options.DiagnosticLogger);
options.NativeSupportCloseCallback = () => Close(options, sentryUnityInfo);

options.DefaultUserId = SentryJava.GetInstallationId(JniExecutor);
if (string.IsNullOrEmpty(options.DefaultUserId))
Expand All @@ -101,15 +103,18 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry
/// <summary>
/// Closes the native Android support.
/// </summary>
public static void Close(IDiagnosticLogger? logger = null)
public static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) =>
Close(options, sentryUnityInfo, ApplicationAdapter.Instance.Platform);

internal static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo, RuntimePlatform platform)
{
if (!SentryJava.IsSentryJavaPresent())
if (!sentryUnityInfo.IsNativeSupportEnabled(options, platform) || !SentryJava.IsSentryJavaPresent())
{
return;
}

// Sentry Native is initialized and closed by the Java SDK, no need to call into it directly
logger?.LogDebug("Closing the sentry-java SDK");
options.DiagnosticLogger?.LogDebug("Closing the sentry-java SDK");

// This is an edge-case where the Android SDK has been enabled and setup during build-time but is being
// shut down at runtime. In this case Configure() has not been called and there is no JniExecutor yet
Expand Down
14 changes: 11 additions & 3 deletions src/Sentry.Unity.iOS/SentryNativeCocoa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent
return crashedLastRun;
};

options.NativeSupportCloseCallback += () => Close(options.DiagnosticLogger);
options.NativeSupportCloseCallback += () => Close(options, sentryUnityInfo, platform);
if (sentryUnityInfo.IL2CPP)
{
options.DefaultUserId = SentryCocoaBridgeProxy.GetInstallationId();
Expand Down Expand Up @@ -81,9 +81,17 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent
/// <summary>
/// Closes the native Cocoa support.
/// </summary>
public static void Close(IDiagnosticLogger? logger = null)
public static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) =>
Close(options, sentryUnityInfo, ApplicationAdapter.Instance.Platform);

internal static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo, RuntimePlatform platform)
{
logger?.LogDebug("Closing the sentry-cocoa SDK");
if (!sentryUnityInfo.IsNativeSupportEnabled(options, platform))
{
return;
}

options.DiagnosticLogger?.LogDebug("Closing the sentry-cocoa SDK");
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved
SentryCocoaBridgeProxy.Close();
}
}
Loading