Video ads implementation causes graphical glitches [Android]

Hi

I’m trying to implement Heyzap ads. I’m passing a current game activity to show ads, something like there:

IncentivizedAd.display(cocosGameActivity);

Rewarded video ads are showing fine, but once I close them, game stars to work incorrectly. It seems like the game is reinitializing: renderer is recreated (EVENT_RENDERER_RECREATED event is sent), textures are reloaded (VolatileTextureMgr::reloadAllTextures is called), services are initialized one more time (for example, SDKBOX sent warning that it has already been initialized), onCreateView is called and so on.

After some pause (black screen), game starts to work fine but with some graphical glitches: random sprites are appearing at random locations, texts are rendered with wrong paramaters, some sprites are at wrong position etc.

Logcat shows tons of errors like:

01-12 19:48:53.522: D/cocos2d-x debug info(25201): OpenGL error 0x0502 in jni/…/…/cocos2d/cocos/./renderer/CCTextureAtlas.cpp drawNumberOfQuads 691
01-12 19:48:53.537: D/cocos2d-x debug info(25201): cocos2d: warning: Uniform at location not found: -1

Can you please answer if that’s an expected behaviour that the game is reset after video ads? How to prevent that? Can you please share any suggestions how to fix my issue?

I believe that’s not a matter of particular ads SDK. I assume that issue may happen because I pass main game activity into ads SDK. Are there any alternatives?

Thanks in advance

Haven’t experienced much for ads SDKs, did you do something in onPause and onResume related to textures?

Usually ads will use the main activity while cocos rendering happens on a separate thread. So normally they won’t effect each other.

How ever if you want to passing data between MainThread(Ads) and GLThread(Cocos) error might happen, since Cocos rendering is not thread safe yet. The most common case is that rewarding the player after video ads finish, since it’s trying to modify data from MainThread to GLThread, and MainThread have no idea what GLThread is doing.

A solution is to wrap the callback code from MainThread with following to make sure it executes on the GLThread

cocos2d::Director::getInstance()->getScheduler()->performFunctionInCocosThread([=](){
}

Thanks a lot for reply. No, I’m not doing anything in onPause and onResume. Currently I dont send any data from Java code to C++.

Why do you think, is that an expected behaviour that once ads are closed the following things are happening: onCreate and onCreateView methods of my game activity are called; renderer is recreated (EVENT_RENDERER_RECREATED is called); VolatileTextureMgr::reloadAllTextures is executed? Even more, according to logs it looks like the game is trying to do everything of these 2-3 times and after several unsuccessful attepts (which takes up to 10 seconds) game resumes with glitches.

If that’s a completely expected behaviour, can glitches be caused by incorrect textures reloading and shaders reinitializations? I’m using lots of custom shaders and custom textures. For example, I’m loading spritesheets, applying lots of shaders to them to change brightness, blur, HUE, color balance etc; and saving them as new textures.

I need to understand what is exactly an issue: either the fact that everything is reloading or the way how I handle that.

I fixed shader reloading and got rid of most of graphical issues

Now I have following problems:

  1. The process of game restoring after ads take 10-15 seconds on my Galaxy S5, which is a lot of time
  2. VolatileTextureMgr::reloadAllTextures is called twice, according to logs. Even if I disable all the shaders.
  3. Labels’ line height is reset. Can be fixed by setting this parameter another time after renderer is recreated, but still looks a bit weird, because I would have to manually reset line height of all labels. Not a critical issue

Any suggestions how to fix these issues or avoid renderer recreation and textures reloading after showing ads?

Fixed everything by adding ‘screenSize’ to android:configChanges, solved

1 Like

Hi, I’ve also integrated Heyzap in a few Android games but never got this glitch, what cocos version are you using?