Unity IOS: InterstitialAd LoadAd freeze the game bug

713 views
Skip to first unread message

memo fayo

unread,
Jul 26, 2016, 4:18:45 AM7/26/16
to Google Mobile Ads SDK Developers
Hello,,
I have problem when using interstitial.LoadAd(request) freeze the game and everything even unity profiler the freezing time depends on internet speed if good will freeze 2 seconds if slow will freeze +7 seconds this problem happen only in IOS .. android works fine,,
i have unity 5.3.6 - Google Mobile Ads Unity Plugin v3.0.5 + Google-Mobile-Ads-SDK (7.9.1) 
i think its a bug
         interstitial = new InterstitialAd(adUnitId);
         
// Create an empty ad request.
         
AdRequest request = new AdRequest.Builder().Build();
         
// Load the interstitial with the request.
         interstitial
.LoadAd(request);  
Regards,,,

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 26, 2016, 11:50:56 AM7/26/16
to Google Mobile Ads SDK Developers
Hi there,

Thank you for letting us know. However, I have been trying to reproduce on Unity 5.3.5f1, Xcode 7.3, Mobile Ads SDK v7.9.1, iPhone 6S, iOS 9.3.2 and throttled data at 256 kbps. The only freeze that occurred was with Video Interstitial playing the video. All of the UI elements were clickable and active. So can you give me more specifics for this? Can you include steps to reproduce or a screen recording if you can?

Thanks,
Veer Busani
Mobile Ads SDK Team

memo fayo

unread,
Jul 26, 2016, 4:27:56 PM7/26/16
to Google Mobile Ads SDK Developers
Hello Veer,,
I recorded test project to see the problem and attached tested code



using UnityEngine;

using System.Collections;

using GoogleMobileAds.Api;

using UnityEngine.UI;





public class test : MonoBehaviour {



    InterstitialAd interstitial;

    int countDownTime = 500;



    [SerializeField]

    Text countDownText;



    private Vector3 xAxis;

    private float secondsForOneLength = 1f;



    void Start () {



        StartCoroutine(countDown());

   

    }

   

    // Update is called once per frame

    void Update () {



        //countDownText.transform.position = new Vector3(yCenter + Mathf.PingPong(Time.time * 2, hight) - hight/2f, transform.position.y, transform.position.z);//move on y axis only

        countDownText.transform.position = new Vector3( Mathf.PingPong(Time.time * 1, 1), transform.position.y, transform.position.z );



        countDownText.text = System.String.Format("{00:00}:{01:00}", Mathf.Floor(countDownTime / 60), countDownTime % 60);



    }



    public void loadAds(){

   

        RequestInterstitial ();

   

    }



    public void showAds(){



        if (interstitial.IsLoaded ()) {

            interstitial.Show ();

            interstitial.Destroy ();



        }

    }



    void RequestInterstitial()

    {

        #if UNITY_ANDROID

        string adUnitId = "ca-app-pub-0000/0000";

        #elif UNITY_IPHONE

        string adUnitId = "ca-app-pub-0000/0000";

        #else

        string adUnitId = "ca-app-pub-0000/00000";

        #endif



        // Initialize an InterstitialAd.


        interstitial = new InterstitialAd(adUnitId);

        // Create an empty ad request.

        AdRequest request = new AdRequest.Builder().Build();

        // Load the interstitial with the request.

        interstitial.LoadAd(request);





    }



    IEnumerator countDown()

    {

        while (countDownTime > 0)

        {

            yield return new WaitForSeconds(1);

            countDownTime--;



        }



    }



}

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 27, 2016, 9:56:40 AM7/27/16
to Google Mobile Ads SDK Developers
Hi there,

Thank you for the details. However, I was unable to reproduce the issue. This now could be a device specific issue. Would you be able to let us the device type and iOS version it's on? The one I have tested was on an iPhone 6S 9.3.2. 

Thanks,
Veer Busani
Mobile Ads SDK Team

memo fayo

unread,
Jul 27, 2016, 1:30:15 PM7/27/16
to Google Mobile Ads SDK Developers
Hello,,
I have tested the game with iPhone 6, iPhone 6 plus with IOS 9.3.2
unity 5.3.6 - Google Mobile Ads Unity Plugin v3.0.5 + Google-Mobile-Ads-SDK (7.9.1) + Xcode Version 7.3.1 (7D1014)

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 27, 2016, 5:17:21 PM7/27/16
to Google Mobile Ads SDK Developers
Hi there,

Here is my screen recording of the same. Notice that there is no UI freeze. Can you send me your sample project itself for us to reproduce? Maybe there is something missing there!

Thanks,
Veer Busani
Mobile Ads SDK Team

memo fayo

unread,
Jul 27, 2016, 11:44:55 PM7/27/16
to Google Mobile Ads SDK Developers
Hello,,
I attached tested project
testfrozen.unitypackage
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

memo fayo

unread,
Jul 28, 2016, 3:56:58 AM7/28/16
to Google Mobile Ads SDK Developers

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 28, 2016, 11:02:38 AM7/28/16
to Google Mobile Ads SDK Developers
Hi there,

Thank you for the project. The issue here is not with our SDK but rather the way you have setup your project, especially by using Coroutines. Here is my analysis - 
  • You must be aware that Unity is not thread safe. Basically means that all processes run with equally shared resources. Nothing gets higher of lower priority, by default. 
  • The way Unity does this is by processing the Update() thread, where it would analyze the inputs for each frame and produce the relevant output. 
  • As all of the processes are given the same importance, the issue now comes with certain tasks where you don't want any analysis to take place and you know what the end result would be, such as animations.
  • Coroutines come into place, where they are memory friendly and easy to execute tasks. However, with Coroutines, instead of concurrently executing tasks on any thread, it would pause/yield itself and give back control to Unity. This is done in certain tasks where the Unity would need more processes and it would tap the Coroutine process by default. 
  • Once the heavy process is completed, the Unity would resume the Coroutine and the whole flow would look like it had paused for a frame. 
Considering this, the single frame pause is expected on that Text. The workaround for this would be to make sure that you are not running any Coroutines while making the AdRequest or pause it if you are using them.

Thanks,
Veer Busani
Mobile Ads SDK Team

memo fayo

unread,
Jul 28, 2016, 2:43:30 PM7/28/16
to Google Mobile Ads SDK Developers
Thank you for explanation,,
I removed all Coroutines from my test project.. only just move text without count down timer however the freezing problem still exists ,, please if you don't mind can provide me your unfrozen project code https://drive.google.com/open?id=0B_ZafC3Djh1RQkhmOVpmYnhOOUE ,, here is my new code 

using UnityEngine;

using System.Collections;

using GoogleMobileAds.Api;

using UnityEngine.UI;





public class test : MonoBehaviour {



    InterstitialAd interstitial;

    int countDownTime = 500;

    [SerializeField]

    Text countDownText;



    // Use this for initialization

    void Start () {


    }

   
    // Update is called once per frame

    void Update () {

        countDownText.transform.position = new Vector3( Mathf.PingPong(Time.time * 1, 1), transform.position.y, transform.position.z );


    }

    public void loadAds(){

        RequestInterstitial ();

    }

    public void showAds(){


        if (interstitial.IsLoaded ()) {



            interstitial.Show ();

            interstitial.Destroy ();

        }

    }



    void RequestInterstitial()

    {

        #if UNITY_ANDROID

        string adUnitId = "ca-app-pub-000/00";

        #elif UNITY_IPHONE

        string adUnitId = "ca-app-pub-000/00";

        #else

        string adUnitId = "ca-app-pub-000/00";


        #endif



        // Initialize an InterstitialAd.

        interstitial = new InterstitialAd(adUnitId);

        // Create an empty ad request.

        AdRequest request = new AdRequest.Builder().Build();

        // Load the interstitial with the request.

        interstitial.LoadAd(request);





    }
}


Regards,,,

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 28, 2016, 5:36:22 PM7/28/16
to Google Mobile Ads SDK Developers
Hi there,

Again I was unable to reproduce the issue. Let me see if I can share any sample app for you. Other than that, you can always make the AdRequest in times where there is not much user interaction. Having said that, I have not been able to reproduce without the use of Coroutines.

Thanks,
Veer Busani
Mobile Ads SDK Team

memo fayo

unread,
Jul 29, 2016, 3:07:45 AM7/29/16
to Google Mobile Ads SDK Developers
Hello,,
I don't know why this problem not seen in android also in previous ios build however same code... i will try to back to previous SDK version
i recorded new video and removed Coroutines
https://youtu.be/8Yxbjievsgc

project link:

Please provide me your code to test it ...

Regards,,

memo fayo

unread,
Jul 29, 2016, 4:55:41 AM7/29/16
to Google Mobile Ads SDK Developers
Ok as i said i get back to previous admob SDK 7.8.1 and test again there is no freeze anymore 
see the video please 
https://youtu.be/tyvGKMrbTt8

so i think there is a bug in version 7.9.1
Regards,,,

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 29, 2016, 11:19:29 AM7/29/16
to Google Mobile Ads SDK Developers
Hi there,

Thank you for the sample app. I did notice a freeze for a frame or two and I will share this with the team. However, I was able to reproduce this on 7.8.1 as well. So this certainly might not be an issue with the SDK but rather the way Unity is handling certain functionalities. In any case, I will update you as soon as I hear more on this.

Thanks,
Veer Busani
Mobile Ads SDK Team

Reply all
Reply to author
Forward
0 new messages