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: IL2CPP in Unity 2023 #1450

Merged
merged 4 commits into from
Sep 26, 2023
Merged
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
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

- Fixed IL2CPP line number processor to no longer crash in Unity 2023 builds ([#1450](https://github.com/getsentry/sentry-unity/pull/1450))

### Dependencies

- Bump Cocoa SDK from v8.10.0 to v8.11.0 ([#1433](https://github.com/getsentry/sentry-unity/pull/1433))
Expand Down
13 changes: 12 additions & 1 deletion package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private Il2CppMethods _il2CppMethods
;
#else
= new Il2CppMethods(
il2cpp_gchandle_get_target,
Il2CppGcHandleGetTargetShim,
Il2CppNativeStackTraceShim,
il2cpp_free);

Expand Down Expand Up @@ -189,10 +189,21 @@ void SwapHexByte(IntPtr buffer, Int32 offset1, Int32 offset2)
return Marshal.PtrToStringAnsi(debugIdPtr);
}

#if UNITY_2023
private static IntPtr Il2CppGcHandleGetTargetShim(IntPtr gchandle) => il2cpp_gchandle_get_target(gchandle);

// Available in Unity `2013.3.12f1` (and later)
// Il2CppObject* il2cpp_gchandle_get_target(Il2CppGCHandle gchandle)
[DllImport("__Internal")]
private static extern IntPtr il2cpp_gchandle_get_target(IntPtr gchandle);
#else
private static IntPtr Il2CppGcHandleGetTargetShim(IntPtr gchandle) => il2cpp_gchandle_get_target(gchandle.ToInt32());

// Available in Unity `2019.4.34f1` (and later)
// Il2CppObject* il2cpp_gchandle_get_target(uint32_t gchandle)
[DllImport("__Internal")]
private static extern IntPtr il2cpp_gchandle_get_target(int gchandle);
#endif

// Available in Unity `2019.4.34f1` (and later)
// void il2cpp_free(void* ptr)
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity/ISentryUnityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Il2CppMethods(
public Il2CppFree Il2CppFree { get; }
}

public delegate IntPtr Il2CppGcHandleGetTarget(int gchandle);
public delegate IntPtr Il2CppGcHandleGetTarget(IntPtr gchandle);
public delegate void Il2CppNativeStackTrace(
IntPtr exc,
out IntPtr addresses,
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity/Il2CppEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private NativeStackTrace GetNativeStackTrace(Exception e)
var addresses = IntPtr.Zero;
try
{
var gchandle = GCHandle.ToIntPtr(gch).ToInt32();
var gchandle = GCHandle.ToIntPtr(gch);
var addr = _il2CppMethods.Il2CppGcHandleGetTarget(gchandle);

var numFrames = 0;
Expand Down