App crashes with error: "too many results to unpack"

Engineering is investigating this.

Rob

Hello! Thanks for reporting.

First of all this crash will be fixed in tomorrow’s daily build, but it is not the best solution.

But it seems that cause of if is having over 8000 listeners to same event. This is clearly result of memory leak, or excessive creating of event listeners. Having this many listeners to very same event will significantly impact performance (it would take several seconds to process) and seems a little bit excessive. Make sure to use removeEventListener when event listener is not needed anymore. Also, 8000 listeners sounds like a lot: make sure you don’t add them recursively. Once listener is added, there is no need to add it again to handle consequent events.

Cheers!

Vlad

Are you sure vlads (if I have understood this wrong then please correct me)?

In my city building game I run a grid of 130x130 tiles and I have 2 events, one for land touch and another for building touch. Each tile will link to one of the other depending on whether it has a building on it or not.  So in my case I could up to 16,900 listeners tied to a single event handler and have never had an issue with it.

Hey, [member=‘Sphere Game Studios’]! In your case you have different events, because objects are different. What wouldn’t work, are very same events , listeners can be different, it doesn’t matter. Basically, you’d have to attach 8k listeners to single tile for tap event, or something.

For example, this wouldn’t work:

[lua]

–Attaching 10k events to same object (demonstrating crash)

local rc = display.newRect(0, 100, 200, 200 )

for i=1, 10000 do

   rc:addEventListener( “tap”, fn )

end

[/lua]

While this is totally OK:

[lua]

– Attaching event to each of 10k objects (works OK)

for i=1, 10000 do

    local rc = display.newRect(0, 100, 200, 200 )

    rc:addEventListener( “tap”, fn )

end

[/lua]

Ah thanks for the explanation.  Instead of hijacking this thread vlads I’m going to send you an email to see if it is something that is possible with Corona.

Thanks for the quick update. 

Just to be clear, the crash occurs when the event is triggered and the object has more than 8000 listeners or when the 8001 listener is being added by “addEventListener”?

Why can’t we see in the stack trace any reference to where in my code it was triggered?

I have no idea why an object would have more than 8000 listeners to the same event in our app… 

Is it possible this event was a Runtime event?

Or maybe it’s a timer event? (Is there a listener added when we call timer.performWithDelay?)

Crash happens when event is dispatched. Adding listeners is fine. Basically, it happens when event has to be dispatched to over 8000 functions/listeners.

Is it possible this has something to do with setting timers (calling timer.performWithDelay)?

We use a lot of timers in the app, and I can’t think of anything else that would have thousands of listeners (not event hundreds…)

Without having code it’s hard for me to say what is going on over there.

Here’s some code which would enclose each event dispatch between “Start dispatching of” and “End dispatching of”. This would produce a lot of output, but ultimately one of your events would have “Start dispatching of” and then “unpack” crash.

[lua]

local dispatch = Runtime.dispatchEvent

getmetatable(Runtime).__index.dispatchEvent = function( obj, event )

  print("Start dispatching of ", event.name)

  dispatch(obj, event)

  print("End dispatching of ", event.name)

end

[/lua]

Note that I edited my previous reply to handle all events, not just those of the Runtime object.

Engineering is investigating this.

Rob

Hello! Thanks for reporting.

First of all this crash will be fixed in tomorrow’s daily build, but it is not the best solution.

But it seems that cause of if is having over 8000 listeners to same event. This is clearly result of memory leak, or excessive creating of event listeners. Having this many listeners to very same event will significantly impact performance (it would take several seconds to process) and seems a little bit excessive. Make sure to use removeEventListener when event listener is not needed anymore. Also, 8000 listeners sounds like a lot: make sure you don’t add them recursively. Once listener is added, there is no need to add it again to handle consequent events.

Cheers!

Vlad

Are you sure vlads (if I have understood this wrong then please correct me)?

In my city building game I run a grid of 130x130 tiles and I have 2 events, one for land touch and another for building touch. Each tile will link to one of the other depending on whether it has a building on it or not.  So in my case I could up to 16,900 listeners tied to a single event handler and have never had an issue with it.

Hey, [member=‘Sphere Game Studios’]! In your case you have different events, because objects are different. What wouldn’t work, are very same events , listeners can be different, it doesn’t matter. Basically, you’d have to attach 8k listeners to single tile for tap event, or something.

For example, this wouldn’t work:

[lua]

–Attaching 10k events to same object (demonstrating crash)

local rc = display.newRect(0, 100, 200, 200 )

for i=1, 10000 do

   rc:addEventListener( “tap”, fn )

end

[/lua]

While this is totally OK:

[lua]

– Attaching event to each of 10k objects (works OK)

for i=1, 10000 do

    local rc = display.newRect(0, 100, 200, 200 )

    rc:addEventListener( “tap”, fn )

end

[/lua]

Ah thanks for the explanation.  Instead of hijacking this thread vlads I’m going to send you an email to see if it is something that is possible with Corona.

Thanks for the quick update. 

Just to be clear, the crash occurs when the event is triggered and the object has more than 8000 listeners or when the 8001 listener is being added by “addEventListener”?

Why can’t we see in the stack trace any reference to where in my code it was triggered?

I have no idea why an object would have more than 8000 listeners to the same event in our app… 

Is it possible this event was a Runtime event?

Or maybe it’s a timer event? (Is there a listener added when we call timer.performWithDelay?)

Crash happens when event is dispatched. Adding listeners is fine. Basically, it happens when event has to be dispatched to over 8000 functions/listeners.

Is it possible this has something to do with setting timers (calling timer.performWithDelay)?

We use a lot of timers in the app, and I can’t think of anything else that would have thousands of listeners (not event hundreds…)

Without having code it’s hard for me to say what is going on over there.

Here’s some code which would enclose each event dispatch between “Start dispatching of” and “End dispatching of”. This would produce a lot of output, but ultimately one of your events would have “Start dispatching of” and then “unpack” crash.

[lua]

local dispatch = Runtime.dispatchEvent

getmetatable(Runtime).__index.dispatchEvent = function( obj, event )

  print("Start dispatching of ", event.name)

  dispatch(obj, event)

  print("End dispatching of ", event.name)

end

[/lua]

Note that I edited my previous reply to handle all events, not just those of the Runtime object.