Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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 .github/workflows/test-run-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
HOMEBREW_NO_INSTALL_CLEANUP: 1
SENTRY_DSN: ${{ secrets.SENTRY_TEST_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_TEST_UNITY_VERSION: ${{ inputs.unity-version }}

steps:
- name: Checkout
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- The SDK no longer throws a `NullReferenceException` during startup on Android and iOS when it can't load its options, for example when the configuration lives in an OBB file that isn't available yet. ([#2931](https://github.com/getsentry/sentry-unity/pull/2931))

## 4.12.0

### Behavioral Changes
Expand Down
14 changes: 12 additions & 2 deletions src/Sentry.Unity.Android/SentryNativeAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,21 @@ void Refresh()
/// <summary>
/// Closes the native Android support.
/// </summary>
public static void Close(SentryUnityOptions options)
public static void Close(SentryUnityOptions? options) =>
Close(options, ApplicationAdapter.Instance.Platform);

// For testing
internal static void Close(SentryUnityOptions? options, RuntimePlatform platform)
{
Logger?.LogInfo("Attempting to close the Android SDK");

if (!options.IsNativeSupportEnabled())
if (options is null)
{
Logger?.LogDebug("No options available. Skipping closing the Android SDK");
return;
}

if (!options.IsNativeSupportEnabled(platform))
{
Logger?.LogDebug("Android Native Support is not enabled. Skipping closing the Android SDK");
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity.MacOS/SentryNativeMacos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void Configure(SentryUnityOptions options)
SentryNativeCocoa.Configure(options);
}

public static void Close(SentryUnityOptions options)
public static void Close(SentryUnityOptions? options)
{
if (options is null)
{
Expand Down
14 changes: 12 additions & 2 deletions src/Sentry.Unity.iOS/SentryNativeCocoa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,21 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
/// <summary>
/// Closes the native Cocoa support.
/// </summary>
public static void Close(SentryUnityOptions options)
public static void Close(SentryUnityOptions? options) =>
Close(options, ApplicationAdapter.Instance.Platform);

// For testing
internal static void Close(SentryUnityOptions? options, RuntimePlatform platform)
{
Logger?.LogInfo("Attempting to close the Cocoa SDK");

if (!options.IsNativeSupportEnabled())
if (options is null)
{
Logger?.LogDebug("No options available. Skipping closing the Cocoa SDK");
return;
}

if (!options.IsNativeSupportEnabled(platform))
{
Logger?.LogDebug("Cocoa Native Support is not enable. Skipping closing the Cocoa SDK");
return;
Expand Down
4 changes: 4 additions & 0 deletions test/IntegrationTest/Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ Describe "Unity $($env:SENTRY_TEST_PLATFORM) Integration Tests" {
Set-ItResult -Skipped -Because "line numbers come from the IL2CPP mappings, which a Mono player does not produce"
return
}
if ($script:Platform -eq "Android" -and $script:TestSetup.UnityVersion -like "2021.3*") {
Set-ItResult -Skipped -Because "on the Android 2021.3 x86_64 emulator, IL2CPP intermittently reports no stack frames for the thrown exception, so the event carries only the throwing frame without a native address"
return
}

$frame = $runEvent.exception.values[0].stacktrace.frames |
Where-Object { $_.module -eq "IntegrationTester" -and $_.function -eq "ThrowException" } |
Expand Down
10 changes: 10 additions & 0 deletions test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NUnit.Framework;
using Sentry.Unity.Tests.SharedClasses;
using Sentry.Unity.Tests.Stubs;
using UnityEngine;

namespace Sentry.Unity.Android.Tests;

Expand Down Expand Up @@ -36,6 +37,15 @@ public void TearDown() =>
Interlocked.Exchange(ref SentryNative.ReinstallSentryNativeBackendStrategy!,
_originalReinstallSentryNativeBackendStrategy)!;

[Test]
public void Close_OptionsNull_DoesNotCloseSentryJava()
{
_testSentryJava.SentryPresent = true;

Assert.DoesNotThrow(() => SentryNativeAndroid.Close(null, RuntimePlatform.Android));
Assert.False(_testSentryJava.CloseCalled);
}

[Test]
public void Configure_DefaultConfiguration_SetsScopeObserver()
{
Expand Down
6 changes: 6 additions & 0 deletions test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace Sentry.Unity.iOS.Tests;

public class SentryNativeCocoaTests
{
[Test]
public void Close_OptionsNull_DoesNotThrow()
{
Assert.DoesNotThrow(() => SentryNativeCocoa.Close(null, RuntimePlatform.IPhonePlayer));
}

[Test]
public void Configure_DefaultConfiguration_iOS()
{
Expand Down
Loading