From a4e60ad6bb5b5ad09aa48076b4b75e71094e7cd0 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 19 May 2017 10:29:52 +0800 Subject: [PATCH 1/2] fix pauseAllEventListenersForTarget couldn't work while dispatching touch event. --- native/cocos/2d/CCNode.cpp | 2 ++ native/cocos/base/CCEventDispatcher.cpp | 4 ++-- native/cocos/base/CCEventListener.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/native/cocos/2d/CCNode.cpp b/native/cocos/2d/CCNode.cpp index ad60e2aa07..b26bdec58d 100644 --- a/native/cocos/2d/CCNode.cpp +++ b/native/cocos/2d/CCNode.cpp @@ -207,6 +207,8 @@ void Node::cleanup() this->stopAllActions(); // timers this->unscheduleAllCallbacks(); + + _eventDispatcher->removeEventListenersForTarget(this); for( const auto &child: _children) child->cleanup(); diff --git a/native/cocos/base/CCEventDispatcher.cpp b/native/cocos/base/CCEventDispatcher.cpp index 5757843afe..cfb4f981ef 100644 --- a/native/cocos/base/CCEventDispatcher.cpp +++ b/native/cocos/base/CCEventDispatcher.cpp @@ -477,9 +477,9 @@ void EventDispatcher::forceAddEventListener(EventListener* listener) associateNodeAndEventListener(node, listener); - if (node->isRunning()) + if (!node->isRunning() && listener->isPaused()) { - resumeEventListenersForTarget(node); + listener->setPaused(true); } } else diff --git a/native/cocos/base/CCEventListener.cpp b/native/cocos/base/CCEventListener.cpp index 02fdd362e5..929938e3be 100644 --- a/native/cocos/base/CCEventListener.cpp +++ b/native/cocos/base/CCEventListener.cpp @@ -41,7 +41,7 @@ bool EventListener::init(Type t, const ListenerID& listenerID, const std::functi _type = t; _listenerID = listenerID; _isRegistered = false; - _paused = true; + _paused = false; _isEnabled = true; return true; From 6c4b055371771f2a90b30b93816940e878475fe2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 19 May 2017 11:02:02 +0800 Subject: [PATCH 2/2] remove unused checking --- native/cocos/base/CCEventDispatcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/base/CCEventDispatcher.cpp b/native/cocos/base/CCEventDispatcher.cpp index cfb4f981ef..455cf600ad 100644 --- a/native/cocos/base/CCEventDispatcher.cpp +++ b/native/cocos/base/CCEventDispatcher.cpp @@ -477,7 +477,7 @@ void EventDispatcher::forceAddEventListener(EventListener* listener) associateNodeAndEventListener(node, listener); - if (!node->isRunning() && listener->isPaused()) + if (!node->isRunning()) { listener->setPaused(true); }