From c69a11296e97672ce87b0a67293fbae2a18b596b Mon Sep 17 00:00:00 2001 From: micahli Date: Mon, 15 Oct 2012 09:55:37 +0800 Subject: [PATCH] fix the potential Container iterator bug with CCNotification revert last fix which may contain other bugs --- cocos2dx/support/CCNotificationCenter.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/cocos2dx/support/CCNotificationCenter.cpp b/cocos2dx/support/CCNotificationCenter.cpp index 17041534ac..2fe860a129 100644 --- a/cocos2dx/support/CCNotificationCenter.cpp +++ b/cocos2dx/support/CCNotificationCenter.cpp @@ -131,22 +131,17 @@ void CCNotificationCenter::unregisterScriptObserver(void) void CCNotificationCenter::postNotification(const char *name, CCObject *object) { - CCArray* intrestedObservers = CCArray::createWithCapacity(m_observers->count()); + CCArray* ObserversCopy = CCArray::createWithCapacity(m_observers->count()); + ObserversCopy->addObjectsFromArray(m_observers); CCObject* obj = NULL; - CCARRAY_FOREACH(m_observers, obj) + CCARRAY_FOREACH(ObserversCopy, obj) { CCNotificationObserver* observer = (CCNotificationObserver*) obj; if (!observer) continue; if (!strcmp(name,observer->getName()) && (observer->getObject() == object || observer->getObject() == NULL || object == NULL)) - intrestedObservers->addObject(observer); - } - - CCARRAY_FOREACH(intrestedObservers, obj) - { - CCNotificationObserver* observer = (CCNotificationObserver*) obj; - observer->performSelector(object); + observer->performSelector(object); } if (m_scriptHandler)