From 36952b29418cf6f9f3de6bd649d5cc3c466af4a3 Mon Sep 17 00:00:00 2001 From: Vaios Kalpias-Ilias Date: Fri, 22 Jan 2016 16:26:39 +0000 Subject: [PATCH] [FIX] Event handlers registered with 'once' called multiple times --- src/core/events.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/events.js b/src/core/events.js index 9d9287319eb..193718366df 100644 --- a/src/core/events.js +++ b/src/core/events.js @@ -143,11 +143,14 @@ pc.events = function () { args = pc.makeArray(arguments); args.shift(); callbacks = this._callbacks[name].slice(); // clone list so that deleting inside callbacks works + var originalIndex = 0; for(index = 0; index < length; ++index) { var scope = callbacks[index].scope; callbacks[index].callback.apply(scope, args); if (callbacks[index].callback.once) { - this._callbacks[name].splice(index, 1); + this._callbacks[name].splice(originalIndex, 1); + } else { + originalIndex++; } } }