Composer bug: Cannot reload scene more than once. (2259)

The reason is that there’s an issue (bug?) with composer in that it can’t reload the current scene without going to another scene first.

If you implement the reload.lua scene I posted above it will work with the one small caveat I mentioned in that post.

thanks a lot ingemar.

at first your template wasn’t working for me as I was trying to call it from within the scene I want to be reloaded. But if I call it from another scene it runs just fine. No caveat to be reported…

Hope the bug get fixed soon…

Thanks again for your help !!

I’m not sure I follow. It should work being called from the current scene (that you want to reload)

I call composer.gotoScene(“reload”) and it reloads whatever scene is currently being displayed. I use it mostly for my scenes when a user changes language. The call to reload is in a button event handler.

So I didn’t misunderstood what I read on this topic: it IS supposed to be called from within the scene you want to reload…

well what I did was at first trying to call it from the scene:show will/did phase of the scene I wanted to reload, and it went all glitchy and crashed the corona simulator (and sublime text too ???). Ok, my mistake, I get it’s supposed to be called from the create scene function? but I can’t do that for the sake of the effect I’m trying to have on screen…

The only solution I managed to find (and keep in mind that I’m shooting in the dark on almost every thing I try since I’m just moving my very first steps in lua and programming in general…) was to call reload.lua from the will/did hide function of the other  scene I’m leaving to get into the one I want to reload.

Weirdly enough this solution reloads the scene I want perfectly, without any glitch occurring.

Now this is only being tested on the simulator so far. In a few days I will get my license to test on devices, so if you think problems might arise with the solution i adopted once on device please let me know in advance…

Thank you very much!!!

This shouldn’t be called within a “will/did show” or “will/did hide” event handler as those mean that you’re already entering/leaving a scene.

It shouldn’t even be called from within a create.

Can you explain what type of scene you’re trying to reload, and why?

well basically I have two scenes worth considering in this case: a start menu (scene1) from which you can access an option screen (scene2). Inside of the option screen there are a few parameters that can be changed to affect the appearance of the start menu. These parameters are checked on the hide scene phase of the scene2.

So basically what happens is: I enter scene2 by hitting a button on scene1. In scene2 change some parameters, hit back button to scene1, this button calls gotoscene1, in the hide phase of scene2 paramters get checked and reload.lua is called.

Results: i get scene1 reloaded with proper changes. Intuitively I’m prone to think this works cause by hitting backbutton we first are sent into scene1 and AFTER that reload is called (and paramaters passed and checked). But as I said concepts aren’t clear enough for me yet as I’m a neophite.

Before this expedient I couldn’t affect scene1 by changing parameters in scene2, no idea why, non of the two is an overlay scene…

What do you think about this??

OK. This is not a case for using my reload.lua as I see it.

In this case, I think you just need to call composer.removeHidden() in your “did show” event in scene2. When you go back to scene1 it should then be reloaded properly.

Just tried, but I need scene1 to be destroyed (-removed) or not based on the parameters that get checked on “did hide” of scene2 and iin “will/did hide” composer.removehidden doesn’t work.

So far using your reload.lua in" scene hide" of scene2 works great for my purpose, is it so bad if keep it this way…???

Why not do:

composer.removeScene(“scene1”)

composer.gotoScene(“scene1”)

from your button handler that closes scene2? 

Edited to add:  Your scene2’s scene:hide() function only happens once the scene starts transitioning away (“will phase”) and again once it’s done transitioning away (“did phase”).  By that point we have already initiated the scene change from a call to composer.gotoScene() and the scene you’re going to has already been constructed (or it’s reusing an existing scene).   You have to handle removing the destination scene before you call gotoScene() and that needs to happen somewhere in your active scene, not in it’s hide or destory events.

Rob

@akak

I didn’t intend for it to be used in such a way, and I’m not sure if there are any unwanted side-effects.

However, if it works, it works. Although I don’t understand why it works  ;). 

Tried it. It’s the same as above, I need scene1 to be removed only if relative parameters get changed and those I only managed to get checked in “hide scene2”.

So if I go ahead and try as you say basically the scene gets detroyed and reloaded regardless of whether something was changed or not in the option screen.

This I’d rather avoid since there’s a specific visual effect I’d like to get: if appareance of scene1 is set to be changed in scene2 once I get back from scene2 to scene1 everything gets ‘rebuilt’ with transitions and such, with a different visual layout. If nothing is set to be changed it just gets back to scene1 smoothly as if scene2 was a sort of overlay (which is not).

The gotcha resides in the fact that the buttons in scene2 are designed to pass a parameter which is a result of a comparison of the state of the buttons when scene2 is entered and when it’s exited.

Hope I got clear enough… Ultimately, the problem is I’m a noob at programming i guess.

ahah. Yes, I’m sorry if I’m ‘bending’ the intent of your template to fit my purpose, but hey, if it works in the end, as you say it’s a win anyway :slight_smile:

Thanks a lot for the help!!!

Then if you don’t need to remove the scene all the time:

if userDidSomethingToRequireASceneChange then

     composer.removeScene(“scene1”)

end

composer.gotoScene(“scene1”)

Rob

Thanks Rob!

As I was discussing with ingemar the matter of the question at this point is where to put something as

if userDidSomethingToRequireASceneChange then

     composer.removeScene(“scene1”)

end

composer.gotoScene(“scene1”)

If   put inside of ‘scene hide’ of scene2 it just won’t work. If put in ‘scene show’ of scene2 it wouldn’t have any info regarding  ‘userDidSomethingToRequireASceneChange’ 'cause those paramaters can be checked only inside of the ‘hide scene2’ function.

That’s basically the catch…

But thanks a lot anyway!!!

Do not put it inside of scene:hide.  It’s too late then.  You have to have something, a button or trigger that says to go back to scene1.  You do this inside whatever is handing that button event.

Rob

Exactly. But that would be too early, cause the function that handles the button event (which triggers go to scene1) doesn’t have the parameters yet to determine whether the scene ( 1 ) needs to be removed or not, because those determining parameters are checked and passed in ‘hide scene2’.

Why do you have to delay the parameters until the hide phase?  Won’t know you when the user selects something to change?

@akak

I hope you don’t mind, but personally I think the logic is a bit off.

I’d remove all checking of parameters from the hide event and put it into its own function. Then on every parameter-button in scene2 that affects scene1 I’d add an event-handler that calls the new parameter-checking function.

It’s cleaner, and that way you don’t need to use reload.lua. You could then use one of the solutions Rob has given you above.

Wow. This is just a real bummer. C’mon Team Corona!!! Make it happen please!!

Love,

The Fella

@Rob, @Ingemar

I moved the ‘check phase’ inside of ‘create scene2’ where everything else about the scene is.

Also made the back button of scene2 to manage whether to simply go back to scene1 if the parameters didn’t change (working), or remove scene 1 and go to scene 1 (rebuild the scene) if some changes occurred (not working).

In this latter case the screen got frozen on scene 2, no error returned. I can hear a specific sound effect of entering scene1 and from this I infer that the parameters have been passed properly and scene1 got loaded, but scene2  is still hanging on the screen. Here’s the function I use to go back to scene1 (it’s triggered by pressing the back button)

--- we're in scene2 and just hit the back button: local  function gotoPlay () --- "Play" would be scene1     if didSTchange == didSTchangeout --- a comparison to determine if changes have been made...    composer.gotoScene ("Play", "zoomInOutFade", 150)     else    composer.removeScene ("Play")    composer.gotoScene ("Play", "zoomInOutFade", 150)     end  end

Any idea regarding the frozen screen?