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

I had to deal with this bug fast because I had to ship an app. My workaround was your exactly the one you have suggested - empty screen to transition to.

I am so glad I never bothered to go to Composer… New & improved Storyboard hah. It will take another 6 months to get Composer as stable as storyboard was/is and by then I bet they will introduce the new iteration… Maestro?  :wink:

I like composer. In general it just cleaned up a lot of little things with storyboard logic. No more purge/remove nonsense, and will/did logic makes more sense than didEnter/willExit/etc. Hopefully this issue gets resolved soon.

I confirmed this bug using 2 scenes to test between (using build 2248):

_ Note: this issue does not occur with storyboard (i tested w/ same scenario)_
 

-- on test1 scene, add to a function composer.removeScene("test2") composer.gotoScene("test2") -- on test2 scene, add to a function composer.removeScene("test1") composer.gotoScene("test1")

One fix i found however, was adding a timer between gotoScene… e.g.

composer.removeScene("test1") timer.performWithDelay(100,function() composer.gotoScene("test1") end)

Or, don’t put code inside scene:create() – put your create code inside functions that are called from inside scene:create().

That way when you want to reload a scene you don’t actually reload – you just call the create code functions again.

Jay

That’s not a bad idea, per se, but is probably an order of magnitude more complicated because:

a) Your code must be sufficiently encapsulated to call outside of createScene, and

b) You would need to write detection code so that your program knows whether to ‘reload’ content within enterScene. So basically do exactly what createScene already does.

The blank scene solution is short (<15 lines), simple, and works well for most cases.

@richard the best solution would be corona fixing it =P

+1. 

Hah, definitely. Fixing that and the hide:did phase would be great.

>.< reverted to storyboard!

Welcome back!  :slight_smile:

I also found that adding a delay fixed the issue for me.

timer.performWithDelay(1,function()
composer.gotoScene(“mainscene”)
end)

Otherwise I’ve found that composer works better than Storyboard.

in which way?

Storyboard events were sometimes firing in an incorrect order (or not at all) causing the app logic to fail.

Composer doesn’t have that problem.

So far I have only seen the issue that the OP has mentioned, but I got around that my issuing the gotoScene() with a 1ms delay as I mentioned above.

That timing fix is very familiar; I wonder if that’s an old regression bug. Anyway, there is an issue with some transition effects (so far I’ve noticed fromX) where the original scene gets dumped before the transition (mixing up will/did somehow, at least visually) but on the whole it has been much cleaner to deal with.

Was this ever resolved? Using a timer doesn’t seem to work for me…

I’ve implemented a blank “dummy” scene called reload.lua to get around the issue.

-- reload.lua -- -- blank scene used for reloading scenes -- local composer = require("composer") local scene = composer.newScene() -- ------------------------------------------------------------------------------- function scene:create(event) local sceneGroup = self.view end function scene:show(event) local sceneGroup = self.view local phase = event.phase if (phase == "did") then composer.removeHidden(true) composer.gotoScene(composer.getSceneName("previous")) end end function scene:hide(event) local sceneGroup = self.view local phase = event.phase end function scene:destroy(event) local sceneGroup = self.view end -- ------------------------------------------------------------------------------- scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) -- ------------------------------------------------------------------------------- return scene

Whenever you want to reload the current scene you just need to call 

composer.gotoScene(“reload”)

It works well, however it does have a small caveat: The screen can sometimes flash briefly between scene changes.

I’ve gotten around that by capturing the screen before reloading, and removing the capture after reloading.

Unfortunately it can’t be done within the reload module as the composer events fire in an order which doesn’t allow the capture to be effective.

Thanks ingemar for that. I ended up doing something similar. I was using 2189, but I take it this still hasn’t been fixed in the newest builds?

Not that I’m aware of…

hey guys,

tried to use this :

composer.removeScene(“test1”)  timer.performWithDelay(100,function() composer.gotoScene(“test1”) end)

inside of scenehide of the scene I’m leaving while going to “test1”, but I only get test1 destroyed and not recreated. I guess that’s the case 'cause I get a black screen and no error returned form the compiler. Any idea why??