FbAudienceNetwork Possible Bug/Leak

Hi there,

I recently registered with facebook for the Facebook Audience Network and did some tests on my iPhone and iPad. I changed my code and replaced the iAd ad I was using with the new facebook ads plugin. I noticed my app was getting increasingly laggy every time I show the ad. I’m assuming maybe there is a bug or memory leak in the plugin itself or I’m doing something wrong. 

In my app, I show a banner ad in the last screen ( like a game over screen ), so I assume I init the plugin on main.lua, then load the ad and show it ( if available ) on the last screen. Then, when the user leaves the last screen, I hide the ad.

I’ve been using code from the docs for the fbAudienceNetwork plugin and the ad is shown properly, but I start getting memory warning after playing the ads 4-5 times. After that, if i continue, my app even crashes. 

Anyone experience this type of thing using this plugin? If you did or will try the plugin, please try getting to a scene where you show the ad multiple times to see if you get leaks as well.

Cheers

HI Marcos,

Can we see the basic code where you load and show the ad? Meaning, exactly where and when you make calls like “.load()” and “.show()” and “.hide()”?

For clarity in the forums, please surround your code with “lua” tags:

[lua] --code [/lua]

Thanks,

Brent

Thanks Brent. So here we go:

Basically on game.lua there is an animation of a rect growing upwards, then I show the ad on gameOver.lua. If you keep going back and forth between game.lua and gameOver.lua, after about 15 times, it starts getting really laggy. Also, xcode throws some errors, especially this one: <Error>: CoreAnimation: failed to allocate IOSurface.

main.lua

[lua]

display.setStatusBar( display.HiddenStatusBar )

local composer = require “composer”

local fbAudienceNetwork = require “plugin.fbAudienceNetwork”

local placementID = “891399177635872_891878497587940”

local adSize = “BANNER_HEIGHT_50”

local function adListener( event )

    if ( event.phase == “init” ) then  – Successful initialization

        print( event.type )

    elseif ( event.phase == “loaded” ) then  – The ad was successfully loaded

        print( event.type )

        print( event.placementId )

        – Show the ad

         fbAudienceNetwork.show( “banner”, placementID, {y = 0}  )

        

    elseif ( event.phase == “failed” ) then  – The ad failed to load

       

    end

end

– Initialize the Facebook Audience Network

fbAudienceNetwork.init( adListener , {“8c57c3feea536ab65c40b5958b71b409ed55ed47”, “36eabd3c0b5e6d63236e74f0911f5353674fe4dd”})

composer.gotoScene( “game”  )

[/lua]

game.lua

[lua]

local composer = require “composer”

local scene = composer.newScene()


– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called.


– local forward references should go here


local bg, circle

local circleTransition

local function changeScene()

    composer.gotoScene( “gameOver” , “fade”, 150 )

end

– “scene:create()”

function scene:create( event )

    local sceneGroup = self.view

    – Initialize the scene here.

    – Example: add display objects to “sceneGroup”, add touch listeners, etc.

    bg = display.newRect( sceneGroup , 0, 0, display.contentWidth, display.contentHeight )

    bg.anchorX, bg.anchorY = 0,0

    bg:setFillColor( 1,1,1,0.87 )

    rect = display.newRect( sceneGroup, display.contentCenterX, display.contentHeight, display.contentWidth, 20 )

    rect.anchorY = 1

    rect:setFillColor( 1,.8,0 )

end

– “scene:show()”

function scene:show( event )

    local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “will” ) then

        – Called when the scene is still off screen (but is about to come on screen).

        circleTransition = transition.to( circle, {radius = 1000, time = 3000} )

    elseif ( phase == “did” ) then

        – Called when the scene is now on screen.

        – Insert code here to make the scene come alive.

        – Example: start timers, begin animation, play audio, etc.

        rect.width = display.contentWidth

        rect.height = 20

        rectTransition = transition.to( rect, { height = display.contentHeight, time = 3000, tag=“trans”, onComplete=changeScene} )

    end

end

– “scene:hide()”

function scene:hide( event )

    local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “will” ) then

        – Called when the scene is on screen (but is about to go off screen).

        – Insert code here to “pause” the scene.

        – Example: stop timers, stop animation, stop audio, etc.

    elseif ( phase == “did” ) then

        – Called immediately after scene goes off screen.

        transition.cancel( “trans” )

    end

end

– “scene:destroy()”

function scene:destroy( event )

    local sceneGroup = self.view

    – Called prior to the removal of scene’s view (“sceneGroup”).

    – Insert code here to clean up the scene.

    – Example: remove display objects, save state, etc.

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene

[/lua]

gameOver.lua

[lua]

local composer = require “composer”

local widget = require “widget”

local fbAudienceNetwork = require “plugin.fbAudienceNetwork”

local scene = composer.newScene()


– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called.


– local forward references should go here


local placementID = “891399177635872_891878497587940”

local adSize = “BANNER_HEIGHT_50”

local bg

local button

local function onButtonRelease(event)

    composer.gotoScene( “game” , “fade”, 150)

    return true

end

– “scene:create()”

function scene:create( event )

    local sceneGroup = self.view

    – Initialize the scene here.

    – Example: add display objects to “sceneGroup”, add touch listeners, etc.

    – Initialize the scene here.

    – Example: add display objects to “sceneGroup”, add touch listeners, etc.

    bg = display.newRect( sceneGroup , 0, 0, display.contentWidth, display.contentHeight )

    bg.anchorX, bg.anchorY = 0,0

    bg:setFillColor( 0,.8,.5 )

    button = widget.newButton( {

        shape = “rect”,

        label = “RESTART GAME”,

        width = 220,

        font = native.systemFontBold,

        fontSize = 22,

        fillColor = {default = {1,.8,0}, over = {1,.8,0,.5}},

        labelColor = {default = {0}, over = {0,0,0,.5}},

        onRelease = onButtonRelease

    } )

    button.anchorX = 0.5

    button.anchorY = 0.5

    button.x = display.contentCenterX

    button.y = display.contentCenterY

   

    sceneGroup:insert(button)

    

end

    

– “scene:show()”

function scene:show( event )

    local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “will” ) then

        – Called when the scene is still off screen (but is about to come on screen).

      

        

    elseif ( phase == “did” ) then

        – Called when the scene is now on screen.

        – Insert code here to make the scene come alive.

        – Example: start timers, begin animation, play audio, etc.

        fbAudienceNetwork.load( “banner”, placementID, adSize )

  

    

    end

end

– “scene:hide()”

function scene:hide( event )

    local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “will” ) then

        – Called when the scene is on screen (but is about to go off screen).

        – Insert code here to “pause” the scene.

        – Example: stop timers, stop animation, stop audio, etc.

        fbAudienceNetwork.hide( placementID )

        

    elseif ( phase == “did” ) then

        – Called immediately after scene goes off screen.

    end

end

– “scene:destroy()”

function scene:destroy( event )

    local sceneGroup = self.view

    – Called prior to the removal of scene’s view (“sceneGroup”).

    – Insert code here to clean up the scene.

    – Example: remove display objects, save state, etc.

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene

[/lua]

And you can get a .zip of this project here.

Thanks again!

Hey Marcos.

Can you email me the crash log from the Xcode console please?

danny@coronalabs.com

Thanks

Done. I just emailed to you. Please let me know if you need anything else. I hope it helps.

Thanks again,

Marcos.

Confirmed fixed.

Thanks again @Marcos Martini for the report.