From e57e6af87f5755d6a5c5696aec4b1d58a7b00e6c Mon Sep 17 00:00:00 2001 From: PP Date: Wed, 29 Aug 2018 16:17:44 +0800 Subject: [PATCH] fix actionManager can't remove all actions (#3159) --- cocos2d/actions/CCActionManager.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cocos2d/actions/CCActionManager.js b/cocos2d/actions/CCActionManager.js index 04566add6e..742fd92ad0 100644 --- a/cocos2d/actions/CCActionManager.js +++ b/cocos2d/actions/CCActionManager.js @@ -145,11 +145,16 @@ cc.ActionManager.prototype = { */ removeAllActions:function () { var locTargets = this._arrayTargets; - for (var i = 0; i < locTargets.length; i++) { - var element = locTargets[i]; + + // RemoveAllActionsFromTarget changes the length of array _arrayTargets. + // So we iterate on the locTargets_clone instead of locTargets. + var locTargets_clone = cc.js.array.copy(locTargets); + for (var i = 0; i < locTargets_clone.length; i++) { + var element = locTargets_clone[i]; if (element) this.removeAllActionsFromTarget(element.target, true); } + locTargets_clone.length = 0; }, /** * !#en