bugsnag / bugsnag-unity

Automatic error reporting for Unity games
https://docs.bugsnag.com/platforms/unity
MIT License
90 stars 31 forks source link

PLAT-10216 prevent JNI call for session and event callbacks if not used #717

Closed richardelms closed 1 year ago

richardelms commented 1 year ago

Goal

prevent JNI call for session and event callbacks if not used.

If there are no C# callbacks then we shouldn't register a native Android callback. This will work around a timing issue for most people as session callbacks aren't widely used.

Changeset

Testing

Manually tested and covered by existing e2e tests

jchowdown commented 1 year ago

Hi, I'm investigating why our bugsnag (7.5.2) is crashing inside AddMetadata. Our callstack looks like this:


0  libc.so +0x8d394        abort
1  libart.so +0x6f3658     art::Runtime::Abort(char const*)
2  libbase.so +0x16ea4     android::base::SetAborter(std::__1::function<void (char const*)>&&)::$_3::__invoke(char const*)
3  libbase.so +0x1644c     android::base::LogMessage::~LogMessage()
4  libart.so +0x3a2ab4     art::JavaVMExt::AddGlobalRef(art::Thread*, art::ObjPtr<art::mirror::Object>)
5  libart.so +0x5e3594     art::JNI<false>::NewGlobalRef(_JNIEnv*, _jobject*)
6  libunity.so +0x123a28   AndroidJNIBindingsHelpers::NewGlobalRef(void*) (libunity)
7  libil2cpp.so +0x511ad44 GlobalJavaObjectRef__ctor_mFE5679D1B51F51CBF11721773C0D767286AC22E8 (libil2cpp)
8  libil2cpp.so +0x511e684 AndroidJavaObject__ctor_m0CEE7D570807333CE2C193A82AB3AB8D4F873A6B (libil2cpp)
9  libil2cpp.so +0x511d2c8 AndroidJavaObject_AndroidJavaObjectDeleteLocalRef_m2ECEEAF6389ABB9D6B963B8A98568ECD9413DF3C (libil2cpp)
10 libil2cpp.so +0x2d95064 AndroidJavaObject__Call_TisRuntimeObject_m6B809BA99521C27E9641C9A6C5C46A3385ED7B14_gshared (libil2cpp)
11 libil2cpp.so +0x5122348 _AndroidJNIHelper_GetSignature_m414A7A6B98FB5565075E4C51F22C482F2BCEEF5F (libil2cpp)
12 libil2cpp.so +0x48d20d0 _AndroidJNIHelper_GetSignature_TisRuntimeObject_m7CC50A493D0C6897ECB2692A7CEFB3A2CD3655A5_gshared (libil2cpp)
13 libil2cpp.so +0x48d1830 _AndroidJNIHelper_GetMethodID_TisRuntimeObject_m7BB44CFD4D80045298CF68828C0FA8F3E1FFE51C_gshared (libil2cpp)
14 libil2cpp.so +0x2d948ec AndroidJavaObject__Call_TisRuntimeObject_m6B809BA99521C27E9641C9A6C5C46A3385ED7B14_gshared (libil2cpp)
15 libil2cpp.so +0x4b4a570 NativeInterface_DictionaryToJavaMap_m1693BD0E35E76B7E299C7695C0774C2F479938C7 (libil2cpp)
16 libil2cpp.so +0x4b43190 NativeInterface_AddMetadata_m4CC3DB5C41CE2198A9BB0F63B4BBF1B7A20EC781 (libil2cpp)
17 libil2cpp.so +0x2c71ba0 Metadata_AddMetadata_m3B9BBF20CF9D4A232ECA182701FC71009EBA2764 (libil2cpp)
18 libil2cpp.so +0x2c375b8 OurCSharpCode_LogSomeStateAsMetadata_m212DF01A6C8D7B2D5C2623669BC31EF5AEB23714 (libil2cpp)

I was wondering if this fix might address our issue (and if so we'll update)?