googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.37k stars 1.08k forks source link

SIGSEGV Libunity.so Crashes #2854

Closed MuhammadWaqasOfficial closed 1 year ago

MuhammadWaqasOfficial commented 1 year ago

Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

We are experiencing lot of crashes and tried everything from changing unity version to different admob version. Almost our every game on play store getting similar crashes. we didn't got any help from unity forums. one thing I didn't tried is removing admob to confirm if it related to admob.

Posting here, might be its related to admob(someone previously posted similar crash #1171 with having DelayedCallManager in backtrace and I am also seeing DelayedCallManager in my crashes trace)


backtrace: 00 /lib/arm/libunity.so (void std::ndk1::tree_balance_after_insert<std::ndk1::tree_node_base<void>>(std::ndk1::tree_node_base<void>, std::ndk1::tree_node_base<void>)) 01 /lib/arm/libunity.so (std::ndk1::tree<DelayedCallManager::Callback, std::ndk1::less, memory_pool>::insert_node_at(std::ndk1::tree_end_node<std::ndk1::tree_node_base<void>>*, std::ndk1::tree_node_base<void>&, std::ndk1::tree_node_base<void>)) 02 /lib/arm/libunity.so (std::ndk1::__tree_iterator<DelayedCallManager::Callback, std::ndk1::tree_node<DelayedCallManager::Callback, void>, int> std::ndk1::tree<DelayedCallManager::Callback, std::__ndk1::less, memory_pool>::emplace_multi<DelayedCallManager::Callback const&>(DelayedCallManager::Callback const&)) 03 /lib/arm/libunity.so (CallDelayed(CallObjectState ()(Object, void), PPtr, float, void, float, CallObjectState ()(void), DelayedCallManager::DelayedCallMode)) 04 /lib/arm/libunity.so (InvokeDelayed(MonoBehaviour&, char const, float, float)) 05 /lib/arm/libunity.so (MonoBehaviour_CUSTOM_InvokeDelayed(ScriptingBackendNativeObjectPtrOpaque, ScriptingBackendNativeStringPtrOpaque, float, float)) 06 /lib/arm/libil2cpp.so (il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const, void*, void)+578) 07 /lib/arm/libil2cpp.so (il2cpp::vm::Runtime::Invoke(MethodInfo const, void, void, Il2CppException)+564) 08 /lib/arm/libil2cpp.so (il2cpp::vm::Runtime::InvokeConvertArgs(MethodInfo const, void, Il2CppObject, int, Il2CppException)+720) 09 /lib/arm/libil2cpp.so (il2cpp::vm::Runtime::InvokeArray(MethodInfo const, void, Il2CppArray*, Il2CppException*)+616) 10 /lib/arm/libil2cpp.so (il2cpp::icalls::mscorlib::System::Reflection::RuntimeMethodInfo::InternalInvoke(Il2CppReflectionMethod, Il2CppObject, Il2CppArray, Il2CppException)+186) 11 /lib/arm/libil2cpp.so (RuntimeMethodInfo_Invoke_m8051178526027CCDA6D5EAC06792B901430EBC70+30568) 12 /lib/arm/libil2cpp.so (MethodBase_Invoke_mEEF3218648F111A8C338001A7804091A0747C826+132) 13 /lib/arm/libil2cpp.so (AndroidJavaProxy_Invoke_m9D765F3E7DC37C5CB14C4884F2873B48D2F96BFB+7277) 14 /lib/arm/libil2cpp.so (_AndroidJNIHelper_InvokeJavaProxyMethod_mCA9BD35B5AE99B6DFABBFE9968DD1EBE931F70C2+54) 15 /lib/arm/libil2cpp.so (RuntimeInvoker_FalseIntPtr_t_RuntimeObject_IntPtr_t_IntPtr_t(void ()(), MethodInfo const, void*, void*, void)+47869) 16 /lib/arm/libil2cpp.so (il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const, void, void)+588) 17 /lib/arm/libil2cpp.so (il2cpp::vm::Runtime::Invoke(MethodInfo const, void, void, Il2CppException*)+564) 18 /lib/arm/libunity.so (scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr, bool)) 19 /lib/arm/libunity.so (ScriptingInvocation::Invoke(ScriptingExceptionPtr, bool)) 20 /lib/arm/libunity.so (UnityJavaProxy_invoke(_JNIEnv, _jobject, long long, _jstring, _jobjectArray)) 21 /oat/arm/base.odex (art_jni_trampoline+156) 22 /apex/com.android.art/lib/libart.so (art_quick_invoke_stub_internal+68) 23 /apex/com.android.art/lib/libart.so (art_quick_invoke_static_stub+276) 24 /apex/com.android.art/lib/libart.so (art::ArtMethod::Invoke(art::Thread, unsigned int, unsigned int, art::JValue, char const)+166) 25 /apex/com.android.art/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread, art::ArtMethod, art::ShadowFrame, unsigned short, art::JValue)+254) 26 /apex/com.android.art/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod, art::Thread, art::ShadowFrame&, art::Instruction const, unsigned short, art::JValue)+738) 27 /apex/com.android.art/lib/libart.so (MterpInvokeStatic+490) 28 /apex/com.android.art/lib/libart.so (mterp_op_invoke_static+20) 29 /data/app/~~Jr0WRqp7pu68WcoavS5_mg==/game.package.name-OSlT_wbwqnDU4_OHTOjcbQ==/oat/arm/base.vdex (com.unity3d.player.ReflectionHelper.a) 30 /apex/com.android.art/lib/libart.so (MterpInvokeStatic+1096) 31 /apex/com.android.art/lib/libart.so (mterp_op_invoke_static+20) 32 /data/app/~~Jr0WRqp7pu68WcoavS5_mg==/game.package.name-OSlT_wbwqnDU4_OHTOjcbQ==/oat/arm/base.vdex (com.unity3d.player.ReflectionHelper$1.invoke+58) 33 /apex/com.android.art/lib/libart.so (art::interpreter::Execute(art::Thread, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.9340319512448905645)+248) 34 /apex/com.android.art/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread, art::CodeItemDataAccessor const&, art::ShadowFrame)+120) 35 /apex/com.android.art/lib/libart.so (artQuickToInterpreterBridge+698) 36 /apex/com.android.art/lib/libart.so (art_quick_to_interpreter_bridge+32) 37 /apex/com.android.art/javalib/arm/boot.oat (java.lang.reflect.Proxy.invoke+68) 38 /apex/com.android.art/lib/libart.so (art_quick_invoke_stub_internal+68) 39 /apex/com.android.art/lib/libart.so (art_quick_invoke_static_stub+276) 40 /apex/com.android.art/lib/libart.so (art::ArtMethod::Invoke(art::Thread, unsigned int, unsigned int, art::JValue, char const)+166) 41 /apex/com.android.art/lib/libart.so (art::JValue art::InvokeWithJValues<art::ArtMethod>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject, art::ArtMethod, jvalue const)+350) 42 /apex/com.android.art/lib/libart.so (art::JValue art::InvokeWithJValues<_jmethodID>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject, _jmethodID, jvalue const)+42) 43 /apex/com.android.art/lib/libart.so (art::JNI::CallStaticObjectMethodA(_JNIEnv, _jclass, _jmethodID, jvalue const)+524) 44 /apex/com.android.art/lib/libart.so (art::InvokeProxyInvocationHandler(art::ScopedObjectAccessAlreadyRunnable&, char const, _jobject, _jobject, std::1::vector<jvalue, std::1::allocator >&)+472) 45 /apex/com.android.art/lib/libart.so (artQuickProxyInvokeHandler+996) 46 /apex/com.android.art/lib/libart.so (art_quick_proxy_invoke_handler+20) 47 /apex/com.android.art/lib/libart.so (art_quick_invoke_stub_internal+68) 48 /apex/com.android.art/lib/libart.so (art_quick_invoke_stub+282) 49 /apex/com.android.art/lib/libart.so (art::ArtMethod::Invoke(art::Thread, unsigned int, unsigned int, art::JValue, char const)+148) 50 /apex/com.android.art/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread, art::ArtMethod, art::ShadowFrame, unsigned short, art::JValue)+254) 51 /apex/com.android.art/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod, art::Thread, art::ShadowFrame&, art::Instruction const, unsigned short, art::JValue)+738) 52 /apex/com.android.art/lib/libart.so (MterpInvokeInterface+892) 53 /apex/com.android.art/lib/libart.so (mterp_op_invoke_interface+20) 54 /data/app/~~Jr0WRqp7pu68WcoavS5_mg==/game.package.name-OSlT_wbwqnDU4_OHTOjcbQ==/oat/arm/base.vdex (com.google.unity.ads.UnityRewardedAd$1$1$4.run+48) 55 /apex/com.android.art/lib/libart.so (art::interpreter::Execute(art::Thread, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.9340319512448905645)+248) 56 /apex/com.android.art/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread, art::CodeItemDataAccessor const&, art::ShadowFrame)+120) 57 /apex/com.android.art/lib/libart.so (artQuickToInterpreterBridge+698) 58 /apex/com.android.art/lib/libart.so (art_quick_to_interpreter_bridge+32) 59 /apex/com.android.art/javalib/arm/boot.oat (java.lang.Thread.run+64) 60 /apex/com.android.art/lib/libart.so (art_quick_invoke_stub_internal+68) 61 /apex/com.android.art/lib/libart.so (art_quick_invoke_stub+282) 62 /apex/com.android.art/lib/libart.so (art::ArtMethod::Invoke(art::Thread, unsigned int, unsigned int, art::JValue, char const)+148) 63 /apex/com.android.art/lib/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject, art::ArtMethod, jvalue const)+374) 64 /apex/com.android.art/lib/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<_jmethodID>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject, _jmethodID, jvalue const)+42) 65 /apex/com.android.art/lib/libart.so (art::Thread::CreateCallback(void)+1056) 66 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void)+40) 67 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)

image CrashList Crash.txt Cleaned_Backtrace.txt

dendyak commented 1 year ago

Did you try to remove all callbacks? I mean callbacks for bannerview or interstitials like OnAdClosed , OnAdFailedToLoad and so on. For now have the same problem for Unity plugin version 7.3.1 and Unity version 2022.2.9

MuhammadWaqasOfficial commented 1 year ago

Did you try to remove all callbacks? I mean callbacks for bannerview or interstitials like OnAdClosed , OnAdFailedToLoad and so on. For now have the same problem for Unity plugin version 7.3.1 and Unity version 2022.2.9

not using callbacks for banner, but for interstitial, rewarded, rewarded interstitial i am using callback. No, i didn't remove them and can't remove them as i need them for rewards/loadnext ad etc.

Today i am giving update of one of my game without admob to see if it is related to admob.

dendyak commented 1 year ago

Did you try to remove all callbacks? I mean callbacks for bannerview or interstitials like OnAdClosed , OnAdFailedToLoad and so on. For now have the same problem for Unity plugin version 7.3.1 and Unity version 2022.2.9

not using callbacks for banner, but for interstitial, rewarded, rewarded interstitial i am using callback. No, i didn't remove them and can't remove them as i need them for rewards/loadnext ad etc.

Today i am giving update of one of my game without admob to see if it is related to admob.

Yes, interesting to find out is it about admob. I will try to use UnityMainThreadDispatcher in all admob-callbacks. (https://github.com/PimDeWitte/UnityMainThreadDispatcher/tree/master)

MuhammadWaqasOfficial commented 1 year ago

Did you try to remove all callbacks? I mean callbacks for bannerview or interstitials like OnAdClosed , OnAdFailedToLoad and so on. For now have the same problem for Unity plugin version 7.3.1 and Unity version 2022.2.9

not using callbacks for banner, but for interstitial, rewarded, rewarded interstitial i am using callback. No, i didn't remove them and can't remove them as i need them for rewards/loadnext ad etc. Today i am giving update of one of my game without admob to see if it is related to admob.

Yes, interesting to find out is it about admob. I will try to use UnityMainThreadDispatcher in all admob-callbacks. (https://github.com/PimDeWitte/UnityMainThreadDispatcher/tree/master)

hey, after months 1 thing i found different from my other games not having crash is MobileAds.RaiseAdEventsOnUnityMainThread = true; Games without crashes have this line. and games with crashes don't have this line. can you confirm with your ad code.

dendyak commented 1 year ago

I never use MobileAds.RaiseAdEventsOnUnityMainThread = true; but will try. I read in other thread that it does not help (https://github.com/googleads/googleads-mobile-unity/issues/2611). That is why I want to try UnityMainThreadDispatcher.

MuhammadWaqasOfficial commented 1 year ago

I never use MobileAds.RaiseAdEventsOnUnityMainThread = true; but will try. I read in other thread that it does not help (#2611). That is why I want to try UnityMainThreadDispatcher.

you can try MobileAds.RaiseAdEventsOnUnityMainThread = true; RequestConfiguration requestConfiguration = new RequestConfiguration.Builder() .SetMaxAdContentRating(GetMaxAdContentRating())//e.g fun return MaxAdContentRating.MA .SetSameAppKeyEnabled(IsPrivacyPolicyAccepted)//true/false based on privacy policy accepted or not. .SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.False) .build();

dendyak commented 1 year ago

thanks i will try

MuhammadWaqasOfficial commented 1 year ago

thanks i will try

i am not using UMP and My admob is 8.2.0

NVentimiglia commented 1 year ago

@MuhammadWaqasOfficial

The stack trace indicates that the crash is originating from the native platform, but does not specifically call out google as the source. The the other participants are correct in suggesting the use of RaiseAdEventsOnUnityMainThread as a work around. Generally native platform calls are dispatched on background threads which cause exceptions if they touch Unity objects. The RaiseAdEventsOnUnityMainThread catches native calls from Google and resends them on the unity main thread so that they are safe.

Please try this out.

MuhammadWaqasOfficial commented 1 year ago

@dendyak thanks for giving the lead/direction to look for. Crash is resolved. @NVentimiglia although this specific backtrace don't give any lead related to admob or google but issue is indirectly related to admob. Adding MobileAds.RaiseAdEventsOnUnityMainThread = true; resolved the issue.

In testing or in most devices it didn't raise any crash but somehow crashes occurred on real players. This crash takes almost 2 to 7 percent of total crash in my every game.

My suggestion is that on developer guide you must mention and force user to set MobileAds.RaiseAdEventsOnUnityMainThread = true; if user is using new ad events and callbacks implementation. As clearly ad events and callbacks directly dependent on RaiseAdEventsOnUnityMainThread value.

I know they mention in developer guide to use MobileAds.RaiseAdEventsOnUnityMainThread = true; for raising events in main thread. But they didn't mention RaiseAdEventsOnUnityMainThread and events has dependency and crash might occur.

If you need any type of crash related data from firebase crashlytics or play console, i will provide.

Regards

NVentimiglia commented 1 year ago

MobileAds.RaiseAdEventsOnUnityMainThread = true;

Thats great, and also confirms that the native calls was google mobile ads.

As a note, Google mobile ads is not thread safe and does not always return events and callbacks on the unity main thread, which can cause issues when touching unity engine objects.

nintendaii commented 8 months ago

Hey guys. I am facing same issue. I tried to add

MobileAds.RaiseAdEventsOnUnityMainThread = true;

But no luck. I was wondering, where should I put this line? Before or after MobilaAds initialization? Maybe the problem is not solved because I put this line before Initialization

dendyak commented 8 months ago
MobileAds.RaiseAdEventsOnUnityMainThread 

in my case only using MobileAdsEventExecutor helps to avoid such crashes: https://github.com/googleads/googleads-mobile-unity/issues/1171#issuecomment-1803197246

nintendaii commented 8 months ago
MobileAds.RaiseAdEventsOnUnityMainThread 

in my case only using MobileAdsEventExecutor helps to avoid such crashes: #1171 (comment)

And where did u put this line? Before or after mobile ads initialization?

dendyak commented 8 months ago
MobileAds.RaiseAdEventsOnUnityMainThread 

in my case only using MobileAdsEventExecutor helps to avoid such crashes: #1171 (comment)

And where did u put this line? Before or after mobile ads initialization?

I use MobileAdsEventExecutor on every callback, including initialization callback. See my comment on other thread: https://github.com/googleads/googleads-mobile-unity/issues/1171#issuecomment-1803197246