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

I suspect we may need to see your code, but consider this.

If you have an image with a touch handler on it and that image is properly inserted into the scene’s view group when that scene transitions off screen (either with a new scene on top of it, or shifted off screen), you can’t interact with that button any more.   Touch listeners on images don’t need to be removed because when the image is removed, the touch listener has no image to be attached too.

You should create any display objects in your scene:create() function and make sure they are inserted into the scene’s view group.

Any runtime listeners, starting of physics, timers, transitions, audio play should be started in the scene:show() event.

Any thing you start in scene:show() needs stopped/paused in scene:hide().  There is very little to do in scene:destroy().  The only thing you would do here is remove anything you loaded in scene:create() like audio that are not automatically removed by scene management.

.

Thanks but I have done all this.

I kind of coded oddly, an object spawns when they touch screen. Then when they release , they toss and when that object collides with another object- both objects are destroyed- removed - set to nil.

So I have an event listener for spawn object that occurs on touch. The touch function then has an event listener called within that which listens for that object to collide.

I create a table in scene:created. This table has values added to it when object spawns , and within the spawn object function, when touch is released- another listener occurs for that object in table to listen when it collided.

Ultimately , the only major runtime event listener is the SpawnObject when the user initially touches the screen- which I remove when scene is destroyed.

The collisioner listener is embedded in that which is directed to that particular table object.

It’s probably a terrible way of coding but I’m just starting out. Im a little reluctant to post code here since there’s more to it then that. I suppose I could just post the ‘objectSpawn’ touch event listener since it’s probably the one that’s giving issue during cleanup.

But all that is in the ‘scene:created’ composer function, which should be deleted when it’s removed and re-launched when scene changes back?

And I’ve checked a hundred times. On collision - my table reference object gets deleted and set to nil- along with the object it collides with.

I’ll re-examine the code tonight, If I still can’t figure it out I’ll post it to the Composer forums.

I been at this for several days now!

I should also note that since I’m spawning objects on touch - I’m creating the physicsBody on touch - because whenever the user touches the screen - it’ll keep spawning objects.  So I created a local table (not in any function) and when the user touches screen - it adds a reference to the table to store the object then creates the physics body for that particular spawned object.

I am using 2393a on my Mac, i did observe that reloading 2nd time doesnt trigger scene:create, scene:hide at all.

this is the flow - 

-create scene called

-scene showed

-in a button handler  - removeScene(current) , gotoScene(current)

for the first time, scene:hide got triggered, but not second time.

You can’t remove the current scene.  It’s still on the screen.  It’s best to either remove a scene just before you go to it, or remove a scene after already in the next scene.  With a little work, you don’t have to remove the scene.  Using the “show”, “will” phase, you can reposition things to their start point.  You should not get a create if the scene hasn’t been removed.  The lack of a hide could be because you are trying to remove the current scene.

Rob

I’m having similar issues as seen in this topic-switching scenes, reloading, etc…  But my code may not be setup correctly…

Majority of the code lies within the ‘Scene:Create’ part of the composer scene.  Should any of this code be placed outside of the Scene Composer functions?  If I’m not going BACK to the scene after removing - the scene works fine.

Then in the ‘Scene:Destory’ section - I have the removal of all my eventListeners.  And the Button removal/nil because it’s a widget (which oddly still does NOT get removed… Tho I have same exact code in Menu for different button that goes to Level1 and that gets removed…??)

So I have a button in Level1 that 'removes “Level1” then goToScene"menu" when button is released… and vice versa for the menu button.

I’m not sure exactly how the code looks now as I’m away from computer with the code.

The issue (and I’m sure it has to do with the garbage collection) is when I go from Level1 back to the Menu.  My tap event listener is still on from level1 tho I removed it in the ‘scene:destory’ function.  This causes some havoc as it’s creating things that shouldn’t be while in the Menu portion that is directly from Level1.  I even tried removing the eventListener within the menu scene - or removing level1 while in menu scene:start and nothing.

Everything else seems to work.  If I start from Menu – nothing happens when I touch outside of button.  When I press Menu button to go to Level1 - it’s a smooth transition, things load correctly - no abnormalities in Level1.  When I hit button to go back to Menu - and I press somewhere on screen that’s not the button to go back to level1 - a touch event is triggered from level1.  I have no touch/tap event listeners in Menu.

Another thing - I have a memory tracking function that prints memory usage that I found on this site.  The memory stays relative with no spikes when I go from Menu --> Level1 and even back to Menu.  However when I go back to Level1 again - the memory load spikes up quite a bit.

Aghh any help / direction would be appreciated, been a nightmare for past few days

I suspect we may need to see your code, but consider this.

If you have an image with a touch handler on it and that image is properly inserted into the scene’s view group when that scene transitions off screen (either with a new scene on top of it, or shifted off screen), you can’t interact with that button any more.   Touch listeners on images don’t need to be removed because when the image is removed, the touch listener has no image to be attached too.

You should create any display objects in your scene:create() function and make sure they are inserted into the scene’s view group.

Any runtime listeners, starting of physics, timers, transitions, audio play should be started in the scene:show() event.

Any thing you start in scene:show() needs stopped/paused in scene:hide().  There is very little to do in scene:destroy().  The only thing you would do here is remove anything you loaded in scene:create() like audio that are not automatically removed by scene management.

.

Thanks but I have done all this.

I kind of coded oddly, an object spawns when they touch screen. Then when they release , they toss and when that object collides with another object- both objects are destroyed- removed - set to nil.

So I have an event listener for spawn object that occurs on touch. The touch function then has an event listener called within that which listens for that object to collide.

I create a table in scene:created. This table has values added to it when object spawns , and within the spawn object function, when touch is released- another listener occurs for that object in table to listen when it collided.

Ultimately , the only major runtime event listener is the SpawnObject when the user initially touches the screen- which I remove when scene is destroyed.

The collisioner listener is embedded in that which is directed to that particular table object.

It’s probably a terrible way of coding but I’m just starting out. Im a little reluctant to post code here since there’s more to it then that. I suppose I could just post the ‘objectSpawn’ touch event listener since it’s probably the one that’s giving issue during cleanup.

But all that is in the ‘scene:created’ composer function, which should be deleted when it’s removed and re-launched when scene changes back?

And I’ve checked a hundred times. On collision - my table reference object gets deleted and set to nil- along with the object it collides with.

I’ll re-examine the code tonight, If I still can’t figure it out I’ll post it to the Composer forums.

I been at this for several days now!

I should also note that since I’m spawning objects on touch - I’m creating the physicsBody on touch - because whenever the user touches the screen - it’ll keep spawning objects.  So I created a local table (not in any function) and when the user touches screen - it adds a reference to the table to store the object then creates the physics body for that particular spawned object.