Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iteration bug in FlxSignal #1420

Merged
merged 2 commits into from
Mar 27, 2015
Merged

Fix iteration bug in FlxSignal #1420

merged 2 commits into from
Mar 27, 2015

Conversation

kevinresol
Copy link
Contributor

There would be array iteration bug if the listener is removed while the signal is processing the array of listeners inside dispatch() (no matter the remove is invoked by dispatchOnce property or by user code through the remove() function)

@Gama11
Copy link
Member

Gama11 commented Mar 26, 2015

What exactly is the bug / got an example that reproduces it?

@kevinresol
Copy link
Contributor Author

In short, the bug appears when you remove() a listener while the signal is dispatch()ing. It is just the classic "remove item while iterating" bug.

var signal = new FlxSignal();
var listener1 = function() trace("L1");
var listener2 = function() trace("L2");
signal.addOnce(listener1);
signal.add(listener2);
signal.dispatch(); // trace: L1 (L1 triggered but not L2 due to the bug)
signal.dispatch(); // trace: L2 (only trigger L2 as L1 already removed)

Gama11 added a commit that referenced this pull request Mar 27, 2015
Fix iteration bug in FlxSignal
@Gama11 Gama11 merged commit e7f3ea5 into HaxeFlixel:dev Mar 27, 2015
Gama11 added a commit that referenced this pull request Mar 27, 2015
Also fixed that the pendingRemove array was not being emptied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants