From 7797fad5a5ef2be4a6f6fd7cf03d77a8a15edbc0 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 19 Sep 2013 10:19:02 +0800 Subject: [PATCH] issue #2087: [EventDispatcher] Fixing crash on Win32. --- cocos2dx/event_dispatcher/CCEventDispatcher.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp index 39504ce6fc..5f51a1b810 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp @@ -166,13 +166,14 @@ void EventDispatcher::removeEventListener(EventListener* listener) return; bool isFound = false; - + for (auto iter = _listeners.begin(); iter != _listeners.end();) { for (auto itemIter = iter->second->begin(); itemIter != iter->second->end(); ++itemIter) { if ((*itemIter)->listener == listener) - { + { + CC_SAFE_RETAIN(listener); (*itemIter)->listener->_isRegistered = false; (*itemIter)->listener->release(); if (_inDispatch == 0) @@ -192,11 +193,10 @@ void EventDispatcher::removeEventListener(EventListener* listener) if (iter->second->empty()) { + _priorityDirtyFlagMap.erase(listener->_type); auto list = iter->second; iter = _listeners.erase(iter); CC_SAFE_DELETE(list); - - _priorityDirtyFlagMap.erase(listener->_type); } else { @@ -206,6 +206,11 @@ void EventDispatcher::removeEventListener(EventListener* listener) if (isFound) break; } + + if (isFound) + { + CC_SAFE_RELEASE(listener); + } } void EventDispatcher::setPriority(EventListener* listener, int fixedPriority)