From ffdd33373655226c48945387c81abfeeaf2c8c23 Mon Sep 17 00:00:00 2001 From: Karl Stenerud Date: Fri, 6 Dec 2024 09:56:34 +0100 Subject: [PATCH] Disable native trace capture on older Unity --- .../Runtime/Native/Cocoa/NativeClient.cs | 23 +++++++++++-------- features/csharp/csharp_events.feature | 1 + features/support/env.rb | 9 ++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Bugsnag/Assets/Bugsnag/Runtime/Native/Cocoa/NativeClient.cs b/Bugsnag/Assets/Bugsnag/Runtime/Native/Cocoa/NativeClient.cs index cf4a4366a..5f8f5031d 100644 --- a/Bugsnag/Assets/Bugsnag/Runtime/Native/Cocoa/NativeClient.cs +++ b/Bugsnag/Assets/Bugsnag/Runtime/Native/Cocoa/NativeClient.cs @@ -489,15 +489,6 @@ public void RegisterForOnSessionCallbacks() NativeCode.bugsnag_registerForSessionCallbacksAfterStart(HandleSessionCallbacks); } - [DllImport("__Internal")] - private static extern IntPtr il2cpp_gchandle_get_target(int gchandle); - - [DllImport("__Internal")] - private static extern void il2cpp_free(IntPtr ptr); - - [DllImport("__Internal")] - private static extern void il2cpp_native_stack_trace(IntPtr exc, out IntPtr addresses, out int numFrames, out IntPtr imageUUID, out IntPtr imageName); - #nullable enable private static string? ExtractString(IntPtr pString) { @@ -535,6 +526,17 @@ private StackTraceLine[] ToStackFrames(System.Exception exception, IntPtr[] nati return stackFrames; } +#if ENABLE_IL2CPP && UNITY_2021_3_OR_NEWER + [DllImport("__Internal")] + private static extern IntPtr il2cpp_gchandle_get_target(int gchandle); + + [DllImport("__Internal")] + private static extern void il2cpp_free(IntPtr ptr); + + [DllImport("__Internal")] + private static extern void il2cpp_native_stack_trace(IntPtr exc, out IntPtr addresses, out int numFrames, out IntPtr imageUUID, out IntPtr imageName); +#endif + public StackTraceLine[] ToStackFrames(System.Exception exception) { var notFound = new StackTraceLine[0]; @@ -544,7 +546,7 @@ public StackTraceLine[] ToStackFrames(System.Exception exception) return notFound; } -#if ENABLE_IL2CPP +#if ENABLE_IL2CPP && UNITY_2021_3_OR_NEWER var hException = GCHandle.Alloc(exception); var pNativeAddresses = IntPtr.Zero; var pImageUuid = IntPtr.Zero; @@ -603,4 +605,5 @@ public StackTraceLine[] ToStackFrames(System.Exception exception) } } } + #endif \ No newline at end of file diff --git a/features/csharp/csharp_events.feature b/features/csharp/csharp_events.feature index b9dfc0af8..598eeed9f 100644 --- a/features/csharp/csharp_events.feature +++ b/features/csharp/csharp_events.feature @@ -31,6 +31,7 @@ Feature: csharp events And expected app metadata is included in the event @ios_only + @skip_before_unity_2021 Scenario: Uncaught Exception ios smoke test When I run the game in the "UncaughtExceptionSmokeTest" state And I wait to receive an error diff --git a/features/support/env.rb b/features/support/env.rb index f3d75ae48..4a0769e64 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -9,6 +9,15 @@ end end +Before('@skip_before_unity_2021') do |_scenario| + if ENV['UNITY_VERSION'] + unity_version = ENV['UNITY_VERSION'][0..3].to_i + if unity_version < 2021 + skip_this_scenario('Skipping scenario on Unity < 2021') + end + end +end + Before('@skip_webgl') do |_scenario| skip_this_scenario('Skipping scenario') unless Maze.config.browser.nil?