Removing enterFrame listeners

I have stumbled upon an issue and would like to know the best way to handle the following situation.

Using the storyboard, I have a scene_gameplay, where many objects are created. In some of the objects I add enterFrame (and other listeners) to Runtime:addEventListener()… All works splendidly.

Inside the scene_gameplay:enterFrame, it detects win/lose/scene change and goes to the next scene; destroying the level, and each object- which the objects override their ‘removeSelf()’ calls to contain Runtime:removeEventListener() to stop listening to events and to destroy any resources the object may have.

Any red flags with that? Because it works; mostly.

It does crash for us at random times but consistently once it happens. (Resources of the object being used after the object was removed). And the best I can figure is Corona’s code has a list of all listeners for enterFrame, and goes through the list calling them one-by-one. The scene_gameplay gets called first, which removes the objects, then the object enterFrame gets called as Corona runs through the list; thus causing a crash because we do not want the object enterFrame to be called anymore.

I tried adding a quick, timer.performWithDelay() to this destroying of the level, but the same thing happened- which makes me believe the timers could just be happening within the enterFrame list, as is a likely way to implement them.

The best ‘solution’ (workaround) we have thought of is to remove the listener in removeSelf and then have another call 1 frame later that does more destruction; like setting the objects to nil.

Is anyone else having issues like this?
Would it be possible to call removeEventListener() in the middle of the list of listeners (enterFrame) being processed - without that removed listener being processed?
[import]uid: 153179 topic_id: 27239 reply_id: 327239[/import]

I don’t think I’m entirely following your description as I think you’re using some unrelated terms, but do you have a code sample which shows the problem or at least what your code is doing in relation to the storyboard?

Right now I would have to guess that you are adding too many of the same listener or simply not actually removing them, but it’s hard to tell without a sample. [import]uid: 8271 topic_id: 27239 reply_id: 110814[/import]