AGK 2.21 crashes on Android if you call the advert system after loading a shader that doesn't exist or has a miss-spelled filename. The app displays a black screen for a long time after closing the ad; sometimes the advert content is corrupted with blocks of colour. Eventually the app will just exit.
The app resumes correctly if the .apk type is set to 'Google'
Good news: SetErrorMode(2) will catch the error but I missed it for a while because I was setting that
after I'd tried to load the shader.
Setting Error Mode to 0 before trying to load a non-existent shader results in a message box that reads "Vertex shader failed to compile: 0:1: L0009: Missing main() function for shader."
Bad news: The crash is silent if you try to load the shader or ads before calling SetErrorMode(). Good thing we have GetLastError() otherwise I might not have found it. Bottom line: Have SetErrorMode() as one of the first lines in your code!
Media-free test code;
- Populate with your own ad credentials
- Export .apk with APK Type set to Amazon
- Run app and wait for "btnRed AdvertLoadedAdMob(): 0" to change to 1.
- Press the red rectangle to show the ad.
- Ad will display with graphics corruption; closing the ad results in a crash.
// Project: Ads
// set window properties
// Batvinks comms code is really useful to repurpose! Thanks Batvink!
SetWindowTitle( "TestAds" )
inAppPurchaseSetTitle(getAppName()) // title of windows
SetWindowSize( 640, 480, 0 )
DW = GetDeviceWidth()
DH = GetDeviceHeight()
myshader = loadspriteshader("whoops_missing_shader.ps")
// set display properties
SetVirtualResolution( DW, DH )
SetOrientationAllowed( 0, 0, 1, 0 )
initAds()
//setErrorMode(0) //no problem if called before loading shader and ads, hard to trace crash if called after or not at all ;)
global glowTween as integer
global btnRed as integer
global btnGreen as integer
global btnBlue as integer
global btnYellow as integer
//Create the tween
glowTween = CreateTweenSprite(0.25)
SetTweenSpriteRed(glowTween,128,255,5)
SetTweenSpriteGreen(glowTween,128,255,5)
// Make the Main screem
spr = CreateSprite(0)
setSpriteSize(spr, 128, 64)
setSpriteColor(spr, 255, 0, 0, 255)
btnRed = spr
spr = CreateSprite(0)
setSpriteSize(spr, 128, 64)
setSpriteColor(spr, 0, 255, 0, 255)
btnGreen = spr
spr = CreateSprite(0)
setSpriteSize(spr, 128, 64)
setSpriteColor(spr, 0, 0, 255, 255)
btnBlue = spr
spr = CreateSprite(0)
setSpriteSize(spr, 256, 96)
setSpriteColor(spr, 255, 255, 0, 255)
btnYellow = spr
SetSpritePositionByOffset(btnRed, getvirtualWidth() / 2 -200, GetVirtualHeight() / 2)
SetSpritePositionByOffset(btnGreen, getvirtualWidth() / 2 , GetVirtualHeight() / 2)
SetSpritePositionByOffset(btnBlue, getvirtualWidth() / 2 +200, GetVirtualHeight() / 2)
SetSpritePositionByOffset(btnYellow, getvirtualWidth() / 2, GetVirtualHeight() / 2 +150)
do
print("fps: " +str(screenfps(),1) )
print("btnRed AdvertLoadedAdMob(): " + str(GetFullscreenAdvertLoadedAdMob()) )
print("btnGreen AdvertLoadedChartboost(): " + str(GetFullscreenAdvertLoadedChartboost()) )
print("btnBlueAdvertLoadedAmazon(): " + str(GetFullscreenAdvertLoadedAmazon()) )
print("GetLast: " + getLastError() )
checkButtonClicks()
updateAllTweens(GetFrameTime())
Sync()
loop
end
//************************************************
function CheckButtonClicks()
//************************************************
// Checks if any buttons were pressed
// If they were, the play an ad
//************************************************
if GetPointerReleased()
hit = GetSpriteHit(getPointerX(), getPointerY())
select hit
case btnRed
ShowFullscreenAdvertAdMob()
PlayTweenSprite(glowTween, btnRed,0)
endcase
case btnGreen
ShowFullscreenAdvertChartboost()
PlayTweenSprite(glowTween, btnGreen,0)
endcase
case btnBlue
ShowFullscreenAdvertAmazon()
PlayTweenSprite(glowTween, btnBlue,0)
endcase
case btnYellow
DisplayAdCascade()
PlayTweenSprite(glowTween, btnYellow,0)
endcase
endselect
endif
if GetRawKeyPressed(13) = 1 //enter key
DisplayAdCascade()
PlayTweenSprite(glowTween, btnYellow,0)
endif
endfunction
function initAds()
SetAdMobDetails("xx-xxx-xxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
SetChartboostDetails("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
SetAmazonAdDetails("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
endfunction
function DisplayAdCascade()
if GetFullscreenAdvertLoadedAdMob() = 1
ShowFullscreenAdvertAdMob()
exitfunction 1
endif
if GetFullscreenAdvertLoadedChartboost() = 1
ShowFullscreenAdvertChartboost()
exitfunction 2
endif
if GetFullscreenAdvertLoadedAmazon() = 1
ShowFullscreenAdvertAmazon()
SetAdvertVisible ( 1 )
exitfunction 3
endif
endfunction 0