Strange Behaviour

Hi All,

I am observing a strange behavior , I have my game.lua where I show a Vungle Ad for an additional life in the game. The flow is something like this

game

All lives Over
show Vungle ad
Vungle Listener adds a life after successful view
Game continues
additional life consumed and game over. Note : My variable no_of_grids = x
Reload this scene to play again
All lives over ( My Variable no_of_grids = y)
Show Vungle Ad
Vungle Listener adds a life after successful view
Game continues

Here is the problem. The game continues with no_of_grids = x !! And reload of a scene (with best practices of removescene, purge scene) is done during the sequence… dont know why the previous scene variables are remembered

this is the reload code :

storyboard.removeScene( “game” )
storyboard.gotoScene( “game”, “fade” , 500 )

Please let me know if this is a mistake from my side

regards
Joel

still drilling down, and simplifying the flow to reproduce the issue - 

 

  • Show Vungle Ad

(now my variable no_of_grids = 5)

  • Ad View is successful, as shown by listener

  • Reload scene

(now my variable no_of_grids is initialized to 0)

  • Show Vungle Ad

(just before beginning, the variable no_of_grids, as expected is 0)

  • Ad View Successful

 

NOW, after the ad view is successful and the control comes back to Corona (after system suspend) , the variable foo is 5. I have no clue why this is happening. I tried different combinations , but whatever I do, the value what I gave in earlier scene is reflecting ! The fact that there is a reload scene and after re-load is correctly set to 0. JUST that when i try to show Vungle ad for a second time , it *somehow* takes the variable values of a old scene !

 

I have written to Vungle as well… anyone with the knowledge of this , please reply! appreciate it :slight_smile:

 

regards,

Joel

I think we are going to need to see some code.  This sounds like a scope issue

local x = 10

if x < 20 then

     local x = 30

end

print(x) – print’s 10.

This can happen by a rogue “local” as scene above, but it can happen from building a closure() type function where it preserves the variable from function call to function call.  And of course you could be doing something globally and writing over it somewhere else.

Rob

Thanks Rob.

I did some more debugging. I see that on every reload of the scene the memory consumption gets increasing although same scene is loaded. I saw a lot of literature around reloading (using gotoscene and inntermediate scene) and i follow most of it.

There is my game.lua. most of the display objects are in display group. Whichever is not , i do a display.remove and nil them out. I nil out all audio handles as well. Also any intermediate display objects (like moving coins and tap to collect them - I nil them out as soon as they are tapped )

I do a removescene of “game” in exitScene so that my main chunk gets re-executed. In the intermediate scene I remove my previous scene again in its createscene and enterscene just to be safe.

I dont closure/anonymous functions (will review again). Is there anything I should take care of while reloading via intermediate scene ? I reload using gotoscene. 

this is a last attempt to find if I have missed anything. Will post my code if you cannot make out anything here!

still drilling down, and simplifying the flow to reproduce the issue - 

 

  • Show Vungle Ad

(now my variable no_of_grids = 5)

  • Ad View is successful, as shown by listener

  • Reload scene

(now my variable no_of_grids is initialized to 0)

  • Show Vungle Ad

(just before beginning, the variable no_of_grids, as expected is 0)

  • Ad View Successful

 

NOW, after the ad view is successful and the control comes back to Corona (after system suspend) , the variable foo is 5. I have no clue why this is happening. I tried different combinations , but whatever I do, the value what I gave in earlier scene is reflecting ! The fact that there is a reload scene and after re-load is correctly set to 0. JUST that when i try to show Vungle ad for a second time , it *somehow* takes the variable values of a old scene !

 

I have written to Vungle as well… anyone with the knowledge of this , please reply! appreciate it :slight_smile:

 

regards,

Joel

I think we are going to need to see some code.  This sounds like a scope issue

local x = 10

if x < 20 then

     local x = 30

end

print(x) – print’s 10.

This can happen by a rogue “local” as scene above, but it can happen from building a closure() type function where it preserves the variable from function call to function call.  And of course you could be doing something globally and writing over it somewhere else.

Rob

Thanks Rob.

I did some more debugging. I see that on every reload of the scene the memory consumption gets increasing although same scene is loaded. I saw a lot of literature around reloading (using gotoscene and inntermediate scene) and i follow most of it.

There is my game.lua. most of the display objects are in display group. Whichever is not , i do a display.remove and nil them out. I nil out all audio handles as well. Also any intermediate display objects (like moving coins and tap to collect them - I nil them out as soon as they are tapped )

I do a removescene of “game” in exitScene so that my main chunk gets re-executed. In the intermediate scene I remove my previous scene again in its createscene and enterscene just to be safe.

I dont closure/anonymous functions (will review again). Is there anything I should take care of while reloading via intermediate scene ? I reload using gotoscene. 

this is a last attempt to find if I have missed anything. Will post my code if you cannot make out anything here!