Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Coroutine crashes app when run from HandleRewardBasedVideoRewarded (Unity AdMob Plugin)

Discussion in 'Scripting' started by jeremydulong, Jul 11, 2018.

  1. jeremydulong

    jeremydulong

    Joined:
    Nov 9, 2017
    Posts:
    11
    I'm not sure if this is the right place to post but I tried stack overflow and got no replies.
    I am trying to run the noAdsReviveCountdown() coroutine as a reward for the player finishing a rewarded video ad but it keeps crashing the app when it hits the call. Commenting out this call causes the video ad works as expected.

    Logs from Xcode just give me "libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper"

    Can I not run a coroutine in the reward handler? I've tried commenting out various parts of the function but it seems even the bare minimum of the coroutine crashes the app.

    Code (CSharp):
    1. // No Ad Revive Countdown function - after 3 seconds the game will resume
    2. public IEnumerator noAdsReviveCountdown() {
    3.  
    4.    continueButton.interactable = false;
    5.    continueText.gameObject.SetActive (false);
    6.    adReviveButton.gameObject.SetActive (false);
    7.    noAdsReviveCountdownText.gameObject.SetActive (true);
    8.  
    9.    timeLeft = 3;
    10.    while (timeLeft >= 0) {
    11.        noAdsReviveCountdownText.text = timeLeft.ToString();
    12.        noAdsReviveCountdownAnim.ResetTrigger ("CountdownTrigger");
    13.        noAdsReviveCountdownAnim.SetTrigger ("CountdownTrigger");
    14.        yield return new WaitForSecondsRealtime(1.0f);
    15.        timeLeft--;
    16.    }
    17.    if (timeLeft < 0) {
    18.        var balls = GameObject.FindGameObjectsWithTag ("ball");
    19.        foreach (var ball in balls) {
    20.            Destroy (ball);
    21.        }
    22.        noAdsReviveCountdownText.gameObject.SetActive (false);
    23.        continueButton.gameObject.SetActive (false);
    24.        Time.timeScale = 1;
    25.    }
    26.  
    27. }
    This coroutine is called here in a separate script that handles all of my AdMob functions:
    Code (CSharp):
    1.     public void HandleRewardBasedVideoClosed(object sender, EventArgs args){
    2.         MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
    3.         if (reward)
    4.             StartCoroutine ( gm.noAdsReviveCountdown() );
    5.         else
    6.             SceneManager.LoadScene (SceneManager.GetActiveScene ().name);
    7.     }
    8.  
    9.     public void HandleRewardBasedVideoRewarded(object sender, Reward args) {
    10.         MonoBehaviour.print( "HandleRewardBasedVideoRewarded event received");
    11.         reward = true;
    12.  
    13.     }
    For more background information, I'm calling the same coroutine in another piece of my code and it works perfectly. This is the case when the user will not see an ad, but skip right to running the coroutine.
    Code (CSharp):
    1.     // Show user a rewarded ad video
    2.     // If the user has paid to remove ads, reward the player without an ad
    3.     public void reviveButtonPressed() {
    4.  
    5.         if (firstLife == true && PlayerPrefs.GetString ("Ads") == "HasAds") {
    6.             gameObject.GetComponent<GoogleMobileAdsBannerScript> ().ShowRewardBasedVideo ();
    7.             firstLife = false;
    8.         } else if (firstLife == true && PlayerPrefs.GetString("Ads") == "NoAds") {
    9.             StartCoroutine ( noAdsReviveCountdown() );
    10.             firstLife = false;
    11.         }
    12.  
    13.     }
    This, coupled with the fact that the ad handler only crashes the app when the coroutine is called, makes me think that the handler somehow cannot run the function properly. But I don't know why.
     
    Last edited: Jul 11, 2018
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    5,217
    Use code tags and show the rest of the script if you can (if it's to large, include the class and where you call the coroutine from and your event, stuff that is relevant to the methods).
     
    jeremydulong likes this.
  3. jeremydulong

    jeremydulong

    Joined:
    Nov 9, 2017
    Posts:
    11
    Thanks for answering Brathnann, I've cleaned up the post and added the handler methods that call the coroutine.
     
    Last edited: Jul 11, 2018
  4. jeremydulong

    jeremydulong

    Joined:
    Nov 9, 2017
    Posts:
    11
    It was a simple mistake after all. The AdMob script was not referencing the gm script to call the coroutine properly. Oops :)
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    5,217
    Glad you were able to get it figured out. :)
     
unityunity