scene management

I tried implementing Ricardo’s Director class into my game. It works great, most of the time, but even with his latest v. 1.2 I can easily crash the simulator *hard* by clicking quickly and repeatedly on the fade button in his example app.

I tried a different, simpler technique of scene management based on a recent example provided by x-pressive, the Particle Candy man. It exposed some very strange bugs that are only visible on the device.

Neither one of these methods seems to handle cleanup reliably or completely, and it’s all too easy to leave timers, handles, etc. dangling in the wind creating memory leaks. The documentation and tools provided by Ansca to discover and fix these problems are also lacking.

Since nearly every app. has at least a couple scenes, I think there should be some kind of in-built method of scene management in Corona. It should handle scene cleanup elegantly and completely and shouldn’t crash the simulator (or the devices). I have no idea what that would look like exposed on the LUA side, all I know is that much better programmers than I have taken a serious crack at it and not entirely succeeded. I don’t see how I can hope to do any better, so this is my plea to Ansca to fill this obvious hole in the API. [import]uid: 9422 topic_id: 6762 reply_id: 306762[/import]

The Director class is very stable. All you have to do is ensure that YOU code for cleaning up of listeners.

For example in the event listener function for a button that should exit a screen I do this:

[blockcode]
local function bt01t ( event )
if event.phase == “ended” then

bt01:removeEventListener(“touch”,bt01t)

director:changeScene(“screen1”,“moveFromLeft”)
end
end
[/blockcode]

By removing the buttons listener you cannot click on it again as the scene changes. There is no memory leak. [import]uid: 9371 topic_id: 6762 reply_id: 23606[/import]

I was just playing with this general issue last night.

If you are “in” an event when you remove an element, even removing the event listener doesn’t prevent a crash.
IE:

I touch an hold a button. Meanwhile, the code executes a removal of the scene with that button. Even removing the event listener, when I let go of the button, there’s a crash because that event listener still gets called to “end”. It needs to be submitted as a bug report, but I haven’t had time. Anyone else care to test this? :slight_smile:
[import]uid: 13859 topic_id: 6762 reply_id: 23615[/import]

@dweezil, actually I don’t have an issue with Director in terms of memory leaks. But I do find it easy to crash so I can’t really call it stable. If you care to, take a look at the demo included with Director 1.2, written by the author himself. Click quickly on the ‘fade’ button rapidly and repeatedly and watch the simulator crap out with a bus error.

Perhaps there’s a more stable way to use Director, but if the author of the module can’t figure out how, there’s no way I’m going to be able to. (The demo also uses ui.lua. Who know’s, maybe the problem’s somewhere in there)

Anyway, my point wasn’t to rag on Director. I just think that the ability to create, transition between, and cleanly remove “scenes”, or whatever you want to call them, is core functionality for almost every kind of app, and a few more Corona functions geared specifically towards doing those things could not only improve reliability but allow for more rapid development.

[import]uid: 9422 topic_id: 6762 reply_id: 23620[/import]

It’s merely an oversight. Just add the code to remove listeners and it’s good to go. [import]uid: 9371 topic_id: 6762 reply_id: 23622[/import]