coronalabs / framework-composer

Corona composer.* framework
https://docs.coronalabs.com/api/library/composer/
2 stars 4 forks source link

Chaining goto calls causes hide events to not occur #4

Closed personalnadir closed 3 years ago

personalnadir commented 3 years ago

Given two scenes A and B. Scene A has a hide event handler.

Scene A calls composer.gotoScene("B"). If in scene B's show handler during the 'will' phase scene B calls composer.gotoScene("C") then the 'did' phase on Scene A's hide handler never occurs.

I have attached an example. Check the terminal output to see the issue

composer.chainedgoto.zip

Shchvova commented 3 years ago

"Will" means that scene is not shown yet. Basically you cancelling it whatsoever. I think this is rather intended behavior, while a little unusual.

Shchvova commented 3 years ago

I will close the issue for now since changing this alters behavior developers may already rely on.

personalnadir commented 3 years ago

Ah, sorry, this isn't about the show event, but the hide event instead. I think the fact that the scene being hidden never receives a hide event with a "did" phase does cause issue. That is when the teardown for the everything setup in the show handler tends to happen. Plus the scene is actually hidden, as you see from the example - scene1 is no longer visible.

I encountered this issue because I had physics objects in the first scene, and was saving data during the hide phase. So I encountered a dual problems: no data saved and phantom physics objects.

It was poor practice on my part - I needed some sort of scene switching solution that handles all the checks and changing of scenes instead of doing it in the scenes themselves.