From 9501faa6c6ceb4c3367b07d7d85450551d679923 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Sat, 27 May 2017 13:55:46 +0800 Subject: [PATCH] fix CCSystemEvent bug for fireball/issues/5821 --- native/cocos/base/CCEventDispatcher.cpp | 28 ++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/native/cocos/base/CCEventDispatcher.cpp b/native/cocos/base/CCEventDispatcher.cpp index 455cf600ad..e0663fcb81 100644 --- a/native/cocos/base/CCEventDispatcher.cpp +++ b/native/cocos/base/CCEventDispatcher.cpp @@ -859,7 +859,33 @@ void EventDispatcher::dispatchCustomEvent(const std::string &eventName, void *op bool EventDispatcher::hasEventListener(const EventListener::ListenerID& listenerID) const { - return getListeners(listenerID) != nullptr; + auto listeners = getListeners(listenerID); + if (listeners == nullptr) + return false; + + if (!_toRemovedListeners.empty()) + { + // fix cocos-creator/fireball/issues/5821 + auto fixedPriorityListeners = listeners->getFixedPriorityListeners(); + auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners(); + for (auto& listener : _toRemovedListeners) + { + if (fixedPriorityListeners) + { + auto matchIter = std::find(fixedPriorityListeners->begin(), fixedPriorityListeners->end(), listener); + if (matchIter != fixedPriorityListeners->end()) + return false; + } + + if (sceneGraphPriorityListeners) + { + auto matchIter = std::find(sceneGraphPriorityListeners->begin(), sceneGraphPriorityListeners->end(), listener); + if (matchIter != sceneGraphPriorityListeners->end()) + return false; + } + } + } + return true; } void EventDispatcher::dispatchTouchEvent(EventTouch* event)