Admob crashing during scene transition after showing ad

I show an interstitial ad before I do a scene transition. I do the transition in the adViewDidDismissScreen method. But the game crashes, I think because of autocaching. If I move the scene transition to adViewDidReceiveAd, there is no crash.

Can I disable auto caching on Admob after showing an ad? I don’t want to be waiting for a new ad to cache before doing a scene transition.

Edit: I can reproduce this pretty reliably, even with test ads enabled.

Step 1:

sdkbox::PluginAdMob::show("interstitial_ad_name");

Step 2:

void ClassicOverlay::adViewDidDismissScreen(const std::string &name) {
auto mainMenu = MainMenu::createScene();
Director::getInstance()->replaceScene(mainMenu);
}

Result:

It does seem to crash at different places (I assume based on how far it gets in the caching process).

sdkbox::AdMobWrapperEnabled::onAdViewWillDismissScreen:

sdkbox::PluginAdMob::getListener at PluginAdMob.cpp:21
0x708c00 <+12>: cbz    r0, 0x708c10              ; <+28> at AdMobWrapper.cpp:156

or:

sdkbox::AdMobWrapperEnabled::onAdViewDidReceiveAd:

sdkbox::PluginAdMob::getListener at PluginAdMob.cpp:21
    0x6ba28e <+12>: cbz    r0, 0x6ba29e              ; <+28> at AdMobWrapper.cpp:119

The error actually displayed is simply EXC_BAD_ACCESS

Just to be definitely sure, have you tried placing

auto mainMenu = MainMenu::createScene();
Director::getInstance()->replaceScene(mainMenu);

in one of these blocks to ensure it is called on the main thread? As Cocos2d-x (I believe anyway!) needs to be run only on the main thread and the callback for when the ad is dismissed may be called from a different thread.

Try something like:

Director::getInstance()->getScheduler()->performFunctionInCocosThread([&]() {
    Director::getInstance()->replaceScene(MainMenu::createScene());
});

Thanks for the suggestion, but it still crashes even with that code.

How are you presenting the advert? Perhaps something is amiss there. If Admob works how I’d expect it to, you initialise Admob (so it can cache an advert), call something to present an advert, and when the advert is exited it should call the dismissedAdvert (or whatever it is called) function. It shouldn’t be waiting on caching - that should occur in the background.

Have you got the most up to date version of Admob? Try running sdkbox update in your project directory.

Yeah I’ve got the latest version of everything. I’m doing what you’ve described: First,

sdkbox::PluginAdMob::init();

triggers adViewDidReceiveAd() once the ad is cached (I don’t have to call for caching the ad myself, init seems to do this)

Then I display the ad:

sdkbox::PluginAdMob::show("my_ad");

When I close the ad, the process of caching another ad is again triggered (again not by me), and adViewDidReceiveAd() goes off when the cache is done.

Is it on iOS or Android?
We’ll look into it and let you know ASAP

This was in iOS, I didn’t attempt it in Android. Thanks for looking into it!

move your listener out of your scene,

class SDKMgr 
{
public:
    AdMobListenerEx *_admobListener;
};

class AdMobListenerEx : public AdMobListener
{

};