Local content isn't removed (exit) when changing scene

Hi guys,

I’m coding an app in Corona for the first time. When I change between scenes in my tabBar widget with 5 views, the local content (a parsed XML message table) from my view1.lua isn’t removed - that is the display objects are still displayed in view2.lua

This problem seems basic, but nonetheless I’m not sure about the coding I’ve made in my view1.lua regarding the scene closing:

_-- Called when scene is about to move offscreen:
function scene:exitScene( event )
    local sceneGroup = self.view
    print(“lol”)
    storyboard.purgeScene( “scene” )
    scene.removeScene()
    storyboard.removeAll()
    – INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
    local sceneGroup = self.view
    print(“lol”)
    – INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.)
end_

It seems like the the above scene functions aren’t even called eventhough I’ve set the correct (?) eventlisteners. The print(“lol”) doesn’t show up in the terminal, instead it prints “nil” when I change from view1.lua to view2.lua (not the other way round).

All codes and files for my app, which is able to run in the simulator, are attached in the uploaded zip file.

Best regards,

Michael

I have 2 guesses, though based on your exit function I don’t think my first guess is the problem:

  1. Objects are not put into the scenes display group, so when you change scene they are not instructed to be removed.

  2. An error is occurring before you even reach the exitScene function. It could be anything, since you haven’t pasted in an error message I’m presuming there is nothing in the terminal to give you a clue? In my experience, when things just stay on the screen (and particularly when parts of the new scene are NOT rendered), it means a Lua error occurred somewhere.

I’m also curious about your exitScene function in general. Is it really set up like this?

storyboard.purgeScene( "scene" ) scene.removeScene() storyboard.removeAll()

Firstly I would avoid calling a scene “scene”, since it could conflict with other objects in storyboard, though I’m aware you could have changed this to avoid typing the real scene name on the forum. 

Also having both scene.removeScene() and storyboard.removeAll() seem unnecessary.

If you are going to a new scene, why would you call storyboard.removeAll() right before that happens?

I have 2 guesses, though based on your exit function I don’t think my first guess is the problem:

  1. Objects are not put into the scenes display group, so when you change scene they are not instructed to be removed.

  2. An error is occurring before you even reach the exitScene function. It could be anything, since you haven’t pasted in an error message I’m presuming there is nothing in the terminal to give you a clue? In my experience, when things just stay on the screen (and particularly when parts of the new scene are NOT rendered), it means a Lua error occurred somewhere.

I’m also curious about your exitScene function in general. Is it really set up like this?

storyboard.purgeScene( "scene" ) scene.removeScene() storyboard.removeAll()

Firstly I would avoid calling a scene “scene”, since it could conflict with other objects in storyboard, though I’m aware you could have changed this to avoid typing the real scene name on the forum. 

Also having both scene.removeScene() and storyboard.removeAll() seem unnecessary.

If you are going to a new scene, why would you call storyboard.removeAll() right before that happens?