From 213be3293207591e626d8a69bfbfc771ffd4f016 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 20 Sep 2013 10:23:58 +0800 Subject: [PATCH] issue #2087: Fixing potential crash reported by Sam Gross. Thanks @Sam. --- cocos2dx/event_dispatcher/CCEventDispatcher.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp index 5f51a1b810..d4a2bef265 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp @@ -175,6 +175,11 @@ void EventDispatcher::removeEventListener(EventListener* listener) { CC_SAFE_RETAIN(listener); (*itemIter)->listener->_isRegistered = false; + if ((*itemIter)->node != nullptr) + { + (*itemIter)->node->dissociateEventListener(listener); + } + (*itemIter)->listener->release(); if (_inDispatch == 0) { @@ -610,6 +615,11 @@ void EventDispatcher::removeListenersForEventType(const std::string& eventType) for (auto iter = listenerItemIter->second->begin(); iter != listenerItemIter->second->end(); ++iter) { (*iter)->listener->_isRegistered = false; + if ((*iter)->node != nullptr) + { + (*iter)->node->dissociateEventListener((*iter)->listener); + } + (*iter)->listener->release(); if (_inDispatch) { @@ -638,6 +648,11 @@ void EventDispatcher::removeAllListeners() for (auto iter = listenerItemIter->second->begin(); iter != listenerItemIter->second->end(); ++iter) { (*iter)->listener->_isRegistered = false; + if ((*iter)->node != nullptr) + { + (*iter)->node->dissociateEventListener((*iter)->listener); + } + (*iter)->listener->release(); if (_inDispatch) {