Null Reference Exception on Android & iOS in LoadAdError.GetMessage()
See original GitHub issue[REQUIRED] Step 1: Describe your environment
- Unity version: 2021.3.1f1
- Google Mobile Ads Unity plugin version: GoogleMobileAds-v7.3.0
- Platform: iOS, Android
- Platform OS version: Android 12, iOS 15.7.1
- Any specific devices issue occurs on: iPhone SE, Poco X3 Pro
- Mediation ad networks used, and their versions: None
[REQUIRED] Step 2: Describe the problem
Steps to reproduce:
Import GoogleMobileAds-v7.3.0 into your project. Subscribe to BannerView.OnAdFailedToLoad and in the subscribed method Debug.Log the result of this method LoadAdError.GetMessage() that is called on OnAdFailedToLoad event argument. Ensure Thread safety. Compile it onto Android & iOS Make conditions so an ad doesn’t load. (turn off your internet connection) Observe the result:
Android: Null Reference Exception in IAdErrorClient inherited class. iOS: Thread 1: EXC_BAD_ACCESS (code=2, address=0x16fc77e80) Application Crash.
Relevant Code:
_bannerView = new BannerView(AdmobConstants.BannerAdUnitId, AdSize.Banner, AdPosition.Top);
_bannerView.OnAdFailedToLoad += FailedToLoadHandler;
private void FailedToLoadHandler(object sender, AdFailedToLoadEventArgs e)
{
YourUnityClass.ExecuteFromMainThread(() =>
{
Debug.Log($"{e?.LoadAdError.GetMessage()}");
});
}
Issue Analytics
- State:
- Created 10 months ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Why do I get a Null Pointer Exception when I try to run ...
When I click the button to call the ad, the program crashes and makes reference to a Null Pointer Exception caused by the...
Read more >NullReferenceException on App.Current.MainPage
that is called from Android native OnMessageReceived() , throws NullReferenceException . Why can this happen? Isn't App.Current to be accessible ...
Read more >Interstitial ads | Android
To load an interstitial ad, call the InterstitialAd static load() method and pass ... Set the ad reference to null so you don't...
Read more >Null Reference Exception error occurs when trying to ...
The main thing it's complaining about is that it doesn't have an <application> tag wrapping the activity.
Read more >FirebaseAuthException - Google
FirebaseAuthMissingActivityForRecaptchaException, Thrown when the auth request attempted to fetch a reCAPTCHA token, but the activity is missing or null.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @mkprivates thanks for raising awareness, I will look deeper into this issue. That said, here is a work around.
Explanation is this could be a race condition related to releasing of resources in IOS.
@Hetagkaty
This error is cause by accessing a native object after it is disposed. This can be solved by making sure the object is accessed in the same frame as it is messaged.