storyboard crash when there is storyboard.purge() in exitScene() and gotoScene is called inside a key handler

Please refer to this topic (I cannot post there for some reason):

http://forums.coronalabs.com/topic/30981-runtime-error-bad-argument-2/

I’m getting this error when I try to use gotoScene

Runtime error
bad argument #-2 to ‘insert’ (Proxy expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘insert’
?: in function ‘?’
?: in function ‘gotoScene’
…ocuments\corona projects\stuck_scenes\guess_word.lua:230: in function
‘_listener’

I came across this error again today in another scene. I discovered that, in the scene I was leaving I was either calling storyboard.purge/remove(“scene”) in the exitScene(). After I removed this it worked fine. I also have a question about memory management, Do I have to manually remove and nil out every table I use? 

Gooner87 is right, I am having this error too. And Gooner87 just saved my day to identify the cause.

I call storyboard.purge(“current theme name”) in exitScene() too.

And it worked perfect until today I try to call gotoScene(“current storyboard name”) in a keyboard pressed handler in my main.lua because I want to handle Android back event. So the scenario is this

(1) Current storyboard, say “Scene 1”

(2) The user presses back key

(3) In my main.lua, a function handles the key event, and checks if current theme is “Scene 1”… if yes, gotoScene(“Scene 2”)

(4)-a If “Scene 1” has storyboard.purge(“Scene 1”) in exitScene(), the error happens (app crashes).

   -b  If “Scene 1” does not have it, no error

   -c  If I call "storyboard.purge(“Scene 1”) in key handling event, no error (but I cannot do this, because I can’t know if I should purge it or not in key handling event, besides if I do, the code structure would become spaghetti)

I think calling storyboard.purge() in exitScene() is quite often and normal? Is this a bad behavior?

Or is this something Corona could fix?

Filled a bug report for this case: Case 28329

Hope Corona can fix this one. Or it’s almost impossible to implement Back key for Android. This case happens so often. Unless purgeScene is not allowed in exitScene?

I know we allow it, but from my experience you really should not purge the existing scene.  exitScene() is called before the scene is transitioned off the screen, but you’re removing it’s display objects.

I find it better to either keep track of the last scene you were in and purge after your in the new scene or before you go to a new scene.

You can turn auto purging on too.

Try it not purging in exitScene() and see if that solves your problem.

Rob

Thanks for the information. It’s very useful since I didn’t know exitScene is called before the scene is transitioned.

After I put purgeScene() in didExitScene(), it works well now.

It is also mentioned in this article:

http://www.coronalabs.com/blog/2012/07/31/storyboard-scene-purging-vs-removal/

Maybe Corona should put this tip in purgeScene() API document. There is another thread that some other user had the same problem.

We will try to update the docs!

Rob

Filled a bug report for this case: Case 28329

Hope Corona can fix this one. Or it’s almost impossible to implement Back key for Android. This case happens so often. Unless purgeScene is not allowed in exitScene?

I know we allow it, but from my experience you really should not purge the existing scene.  exitScene() is called before the scene is transitioned off the screen, but you’re removing it’s display objects.

I find it better to either keep track of the last scene you were in and purge after your in the new scene or before you go to a new scene.

You can turn auto purging on too.

Try it not purging in exitScene() and see if that solves your problem.

Rob

Thanks for the information. It’s very useful since I didn’t know exitScene is called before the scene is transitioned.

After I put purgeScene() in didExitScene(), it works well now.

It is also mentioned in this article:

http://www.coronalabs.com/blog/2012/07/31/storyboard-scene-purging-vs-removal/

Maybe Corona should put this tip in purgeScene() API document. There is another thread that some other user had the same problem.

We will try to update the docs!

Rob