You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brief summary of issue / Description of requested feature:
When nesting a call to registerAnonymousEventHandler, a single call to raiseEvent("testEvent", 999) will fire both the parent and nested handlers simultaneously. This seems counter intuitive, and can lead to an unexpected infinite loop and stack overflow issue in more complex use cases. The example below is a trivial oversimplification only meant to demonstrate the problem.
local handlerId1
handlerId1 = registerAnonymousEventHandler("testEvent", function(event, i)
cecho("HANDLER1: " .. tostring(i) .. "\n")
local handlerId2
handlerId2 = registerAnonymousEventHandler("testEvent", function(event, i)
cecho("HANDLER2: " .. tostring(i) .. "\n")
killAnonymousEventHandler(handlerId1 or 0)
killAnonymousEventHandler(handlerId2 or 0)
end)
end)
Steps to reproduce the issue / Reasons for adding feature:
Call raiseEvent("testEvent", 999) a single time
Both event handler 1 and event handler 2 are executed simultaneously for the single event that was fired.
Error output / Expected result of feature
I would expect that it only fires the outer/parent event handler for the first call to raiseEvent. A second call to raiseEvent should fire the inner event handler since it is registered after the first event is fired.
Extra information, such as the Mudlet version, operating system and ideas for how to solve / implement:
On your side, I would suggest cloning the list of registered event handlers before you iterate over them to process a raiseEvent call, so that they remain stable during this time, and so that it doesn't automatically process new event handlers added to the tail end of your list (which is what is currently occuring when the new event handler is added inside the parent event handler).
The text was updated successfully, but these errors were encountered:
Brief summary of issue / Description of requested feature:
When nesting a call to registerAnonymousEventHandler, a single call to raiseEvent("testEvent", 999) will fire both the parent and nested handlers simultaneously. This seems counter intuitive, and can lead to an unexpected infinite loop and stack overflow issue in more complex use cases. The example below is a trivial oversimplification only meant to demonstrate the problem.
Steps to reproduce the issue / Reasons for adding feature:
Error output / Expected result of feature
I would expect that it only fires the outer/parent event handler for the first call to raiseEvent. A second call to raiseEvent should fire the inner event handler since it is registered after the first event is fired.
Extra information, such as the Mudlet version, operating system and ideas for how to solve / implement:
On your side, I would suggest cloning the list of registered event handlers before you iterate over them to process a raiseEvent call, so that they remain stable during this time, and so that it doesn't automatically process new event handlers added to the tail end of your list (which is what is currently occuring when the new event handler is added inside the parent event handler).
The text was updated successfully, but these errors were encountered: