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

Crashes on Android: Global reference table overflow #2679

Closed Davidnovarro closed 1 year ago

Davidnovarro commented 1 year ago

I'm getting crash reports related to loading Interstitial ads from the Google Play dashboard. Here is a dump: JNI ERROR (app bug): global reference table overflow (max=51200)global reference table dump:


pid: 0, tid: 11865 >>> com.cooperbit.brawlparty <<<

backtrace:

00 pc 0x000000000008bebc /apex/com.android.runtime/lib64/bionic/libc.so (abort+168)

01 pc 0x00000000006f9f28 /apex/com.android.art/lib64/libart.so (art::Runtime::Abort(char const*)+472)

02 pc 0x0000000000016ea8 /apex/com.android.art/lib64/libbase.so (android::base::SetAborter(std::__1::function<void (char const)>&&)::$_3::__invoke(char const)+80)

03 pc 0x0000000000016450 /apex/com.android.art/lib64/libbase.so (android::base::LogMessage::~LogMessage()+352)

04 pc 0x00000000003a3294 /apex/com.android.art/lib64/libart.so (art::JavaVMExt::AddGlobalRef(art::Thread*, art::ObjPtr)+1908)

05 pc 0x00000000005e56c4 /apex/com.android.art/lib64/libart.so (art::JNI::NewGlobalRef(_JNIEnv, _jobject)+160)

06 pc 0x0000000000114520 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (AndroidJNIBindingsHelpers::NewGlobalRef(void*))

07 pc 0x0000000002813e48 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (GlobalJavaObjectRef__ctor_mFE5679D1B51F51CBF11721773C0D767286AC22E8)

08 pc 0x0000000002817850 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (AndroidJavaObject__ctor_m0CEE7D570807333CE2C193A82AB3AB8D4F873A6B)

09 pc 0x00000000028163cc /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (AndroidJavaObject_AndroidJavaObjectDeleteLocalRef_m2ECEEAF6389ABB9D6B963B8A98568ECD9413DF3C)

10 pc 0x000000000105257c /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (AndroidJavaObject__Call_TisRuntimeObject_m6B809BA99521C27E9641C9A6C5C46A3385ED7B14_gshared)

11 pc 0x000000000281b538 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (_AndroidJNIHelper_GetSignature_m414A7A6B98FB5565075E4C51F22C482F2BCEEF5F)

12 pc 0x000000000281a610 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (_AndroidJNIHelper_GetSignature_m309D35CC998B59CFEDA2D6EB5D0E221B3F1374F7)

13 pc 0x0000000002816924 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (AndroidJavaObject__AndroidJavaObject_m1284CB7198514B8C06A2BF794ACDC909DC26443F)

14 pc 0x0000000001f7cf1c /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (InterstitialClient__ctor_m0046CDB719B03D590B6E356A884B10D1EAF173E5)

15 pc 0x0000000001f7cca4 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (GoogleMobileAdsClientFactory_BuildInterstitialClient_mBA16B22AAB2CA58F48437FAADA0DCEB4C1FAA1CE)

16 pc 0x0000000001f87d88 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (InterstitialAd_Load_m7582DD601991C297C7E7E61BBE53B639466A73A1)

17 pc 0x00000000008bc2ac /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (Tools_SafeInvoke_TisInterstitialAd_t41640B3957C2B66FA5F6F38A4805393B6B013FEC_TisLoadAdError_t22654493F27C801157B803019F04E69E66CD4A62_mE9DD453EE093B788707696645BE1DD3B77785CAB_inline(Action_2_t6D103D50D92EED8806671DABC525008F7D560A68, InterstitialAd_t41640B3957C2B66FA5F6F38A4805393B6B013FEC, LoadAdError_t22654493F27C801157B803019F04E69E66CD4A62, MethodInfo const))

18 pc 0x0000000001f86050 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (MobileAdsEventExecutor_Update_mA2FA865A80DE36FC26CAD15783037324C74D5113)

19 pc 0x0000000000ad6650 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const, void, void**))

20 pc 0x0000000000ad64c4 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libil2cpp.so (il2cpp::vm::Runtime::Invoke(MethodInfo const, void, void, Il2CppException))

21 pc 0x00000000002fd978 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool))

22 pc 0x000000000030c588 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool))

23 pc 0x0000000000319f64 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (MonoBehaviour::CallUpdateMethod(int))

24 pc 0x000000000018e58c /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (void BaseBehaviourManager::CommonUpdate())

25 pc 0x000000000022c5d0 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (ExecutePlayerLoop(NativePlayerLoopSystem*))

26 pc 0x000000000022c610 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (ExecutePlayerLoop(NativePlayerLoopSystem*))

27 pc 0x000000000022c848 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (PlayerLoop())

28 pc 0x0000000000387250 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (UnityPlayerLoop())

29 pc 0x000000000039d684 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/lib/arm64/libunity.so (nativeRender(_JNIEnv, _jobject))

30 pc 0x00000000000777a4 /data/app/~~kwV9ONBX0eRZ4MofoZqsOQ==/com.cooperbit.brawlparty-QY6nTh2-ebhv2N81Olb8ew==/oat/arm64/base.odex

NVentimiglia commented 1 year ago

Hi @Davidnovarro

To confirm, you are not able to replicate this issue locally and it only appears on the google play dashboard? If so, can you create a support ticket here? please include your publisher id, app id, and a link to issue. A minimal sample app would also be helpful.

DevDreams12 commented 1 year ago

same problem

Davidnovarro commented 1 year ago

After an investigation, I found out that the issue was mostly in some countries, and on some devices where no ad was returned by Admob. And in those cases, I was constantly requesting new ads right after the "ad failed to load" response.

I've added an exponential delay (2 seconds, 4s, 8s, 16...) before retrying and I confirm fixed the problem.

This issue can be closed.

DevDreams12 commented 1 year ago

Can you show example of implementation for interstitial ad load with delay like you described. I would be very thankful because I'm getting a lot of crash reports from my game because this issue.

Davidnovarro commented 1 year ago

You can do something like this

void OnRewardedAdFailedEvent()
{
          // Rewarded ad failed to load. We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds).
          rewardedRetryAttempt++;
          double retryDelay = Math.Pow(2, Math.Min(6, rewardedRetryAttempt));
          Invoke("LoadRewardedAd", (float) retryDelay);
}
DevDreams12 commented 1 year ago

I have implemented it yesterday like this and the crashes table overflow are gone with new version:

private void SetInterstitialAdEvent() { _interstitialAd.OnAdClosed += (sender, args) => { StartLoadingCoroutine(); }; _interstitialAd.OnAdFailedToLoad += (sender, args) => { StartLoadingCoroutine(); }; }

private void StartLoadingCoroutine()
{
    if (loadingCoroutine != null)
    {
        StopCoroutine(loadingCoroutine);
    }
    loadingCoroutine = StartCoroutine(ExponentialDelayCoroutine());
}

private IEnumerator ExponentialDelayCoroutine()
{
    float delay = 1f; // Start delay (1 second)

    while (!_interstitialAd.IsLoaded())
    {
        Debug.Log("Interstitial ad is not loaded. Retrying in " + delay + " seconds...");
        yield return new WaitForSeconds(delay);

        delay *= 2; // Exponential delay (double the previous delay)
        if (delay > 16f)
        {
            delay = 16f; // Cap the delay at 16 seconds
        }

        _interstitialAd.LoadAd(new AdRequest.Builder().Build());
    }
}

public void ShowInterstitialAd()
{
    if (_interstitialAd != null && _interstitialAd.IsLoaded())
    {
        Debug.Log("Showing interstitial ad....");
        _interstitialAd.Show();
    }
    else
    {
        Debug.LogError("Interstitial ad is not ready yet.");
    }
}`
DevDreams12 commented 1 year ago

What do you think? Good Solution for efficiency or adding like you delay till 64 seconds not max 16 seconds?

Davidnovarro commented 1 year ago

What do you think? Good Solution for efficiency or adding like you delay till 64 seconds not max 16 seconds?

I would increase the delay untill 1 minute.

DevDreams12 commented 1 year ago

Quick Update:

I have updated the plugin because of ANRs to 8.2.0 but now my implementation with delay don't work anymore. Can you please show me full solution of your implementation? I would be very thankful because now my players getting table overflow crashes again. Over 1k gettings these crashes again

Davidnovarro commented 1 year ago

My solution is complicated with a lot of abstraction, not sure if that would make your life easier but anyways I can send it in a zipped folder if you'll leave your email here, so you can figure it out by yourself.

But overall you should call "LoadAd: once and on "Failed Callback" you should check how many attempts were done previously and based on that number calculate a delay.

Here is a simple example from Applovin https://dash.applovin.com/documentation/mediation/unity/ad-formats/interstitials

DevDreams12 commented 1 year ago

Thats my E-Mail: champstudios02@gmail.com. Thank you brother!

Davidnovarro commented 1 year ago

Thats my E-Mail: champstudios02@gmail.com. Thank you brother!

Done, also I forgot to mention that you need to call Destroy() methods on ad instances.