Googleads-mobile-unity: On Unity Editor, InitializationStatus.client == null, which leads to some errors

Created on 19 May 2020  路  6Comments  路  Source: googleads/googleads-mobile-unity

On Editor, calling InitializationStatus.getAdapterStatusMap(), or similar functions, returns a null pointer exception error

https://github.com/googleads/googleads-mobile-unity/blob/992050ac91bd9510ed8d36de7b4cf497a4fae174/source/plugin/Assets/GoogleMobileAds/Common/DummyClient.cs#L76-L80

I discovered this while doing
```C#

UNITY_EDITOR

MobileAds.Initialize( (InitializationStatus initStatus)=>{
var map = initStatus.getAdapterStatusMap(); // Error, null pointer exception, because initStatus.client == null
});
```
https://github.com/googleads/googleads-mobile-unity/blob/992050ac91bd9510ed8d36de7b4cf497a4fae174/source/plugin/Assets/GoogleMobileAds/Api/InitializationStatus.cs#L34-L37

Most helpful comment

The tagged CLs resolve this. The next release is due in the coming week and will contain this fix.

All 6 comments

I was using an older AdMob plugin (4.2.1 I think), just updated today to the latest (5.2.0) and started getting this exception every time I try to launch my game on Unity (Editor) to test anything... this seems to be a pretty serious and consistent bug (happens 100% of the time for me), I dont understand why it's ignored.

Here is the stacktrace I get upon launching my game:

NullReferenceException: Object reference not set to an instance of an object
GoogleMobileAds.Api.InitializationStatus.getAdapterStatusMap () (at Assets/GoogleMobileAds/Api/InitializationStatus.cs:36)
MyGameAdModule.b__43_0 (GoogleMobileAds.Api.InitializationStatus initStatus) (at Assets/_Game/_Scripts/Managers/MyGameAdModule.cs:130)
GoogleMobileAds.Api.MobileAds+<>c__DisplayClass7_0.b__0 (GoogleMobileAds.Common.IInitializationStatusClient initStatusClient) (at Assets/GoogleMobileAds/Api/MobileAds.cs:71)
GoogleMobileAds.Common.DummyClient.Initialize (System.Action 1[T] initCompleteAction) (at Assets/GoogleMobileAds/Common/DummyClient.cs:79)
GoogleMobileAds.Api.MobileAds.Initialize (System.Action 1[T] initCompleteAction) (at Assets/GoogleMobileAds/Api/MobileAds.cs:66)
MyGameAdModule.InitializeOnScreenStart () (at Assets/_Game/_Scripts/Managers/MyGameAdModule.cs:128)
UnityEngine.Debug:LogException(Exception)

Obs: I dont know if it's related to my game/setup, so I'll add more info: I use open bidding on Facebook, and have just updated their mediation adapter as well (2.9.2 if I recall correctly). I initialize AdMob using this code:

`

        MobileAds.Initialize((initStatus) =>
        {
            Dictionary<string, AdapterStatus> map = initStatus.getAdapterStatusMap();
            foreach (KeyValuePair<string, AdapterStatus> keyValuePair in map)
            {
                string className = keyValuePair.Key;
                AdapterStatus status = keyValuePair.Value;
                switch (status.InitializationState)
                {
                    case AdapterState.NotReady:
                        // The adapter initialization did not complete.
                        MonoBehaviour.print("Adapter: " + className + " not ready --> " + status.Description);
                        break;
                    case AdapterState.Ready:
                        if (className != null && className.Contains("FacebookMediationAdapter"))
                            adapterFacebookEnabled = true;
                        // The adapter was successfully initialized.
                        MonoBehaviour.print("Adapter: " + className + " is initialized.");
                        break;
                }
            }
        });

`

Any updates? Still getting this exception every time I launch my games on the Editor...

The tagged CLs resolve this. The next release is due in the coming week and will contain this fix.

Thanks!!!

In the mean time you can reduce the annoyingness of this issue with the compile time commands of unity:
https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
kinda like this

Dictionary<string, AdapterStatus> statusMap;
#if !UNITY_EDITOR
statusMap = InitializationStatus.getAdapterStatusMap();
#endif
if (statusMap != null) ///do stuff

Release 5.3.0 has this in it.

Was this page helpful?
0 / 5 - 0 ratings