fix a bug with CCNotificationCenter that observer->performSelector(observer) may call CCNotificationCenter::removeObserver and cause CCARRAY_FOREACH(m_observers, obj) access invalid address

This commit is contained in:
micahli 2012-10-13 16:44:46 +08:00
parent 8b650794e6
commit 7d1d46ee3f
1 changed files with 8 additions and 1 deletions

View File

@ -131,6 +131,7 @@ void CCNotificationCenter::unregisterScriptObserver(void)
void CCNotificationCenter::postNotification(const char *name, CCObject *object)
{
CCArray* intrestedObservers = CCArray::createWithCapacity(m_observers->count());
CCObject* obj = NULL;
CCARRAY_FOREACH(m_observers, obj)
{
@ -139,7 +140,13 @@ void CCNotificationCenter::postNotification(const char *name, CCObject *object)
continue;
if (!strcmp(name,observer->getName()) && (observer->getObject() == object || observer->getObject() == NULL || object == NULL))
observer->performSelector(object);
intrestedObservers->addObject(observer);
}
CCARRAY_FOREACH(intrestedObservers, obj)
{
CCNotificationObserver* observer = (CCNotificationObserver*) obj;
observer->performSelector(object);
}
if (m_scriptHandler)