mirror of https://github.com/axmolengine/axmol.git
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:
parent
8b650794e6
commit
7d1d46ee3f
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue