mirror of https://github.com/axmolengine/axmol.git
CCEventDispatcher crash fix
Fix possible crashes which could be caused by the EventDispatcher having listeners associated with nodes are destroyed. Catch the case where a node registers a listener while we are dispatching events and gets destroyed while that event is still being dispatched. Check the list of nodes to be added into the event dispatcher fully when we are cleaning listeners for a target node. This issue was found using the extra debug verification in this pull request: https://github.com/cocos2d/cocos2d-x/pull/6011
This commit is contained in:
parent
f9ac3c82fc
commit
79b5dff795
|
@ -340,6 +340,26 @@ void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive
|
|||
}
|
||||
}
|
||||
|
||||
// Bug fix: ensure there are no references to the node in the list of listeners to be added.
|
||||
// If we find any listeners associated with the destroyed node in this list then remove them.
|
||||
// This is to catch the scenario where the node gets destroyed before it's listener
|
||||
// is added into the event dispatcher fully. This could happen if a node registers a listener
|
||||
// and gets destroyed while we are dispatching an event (touch etc.)
|
||||
for (auto iter = _toAddedListeners.begin(); iter != _toAddedListeners.end(); )
|
||||
{
|
||||
EventListener * listener = *iter;
|
||||
|
||||
if (listener->getSceneGraphPriority() == target)
|
||||
{
|
||||
listener->release();
|
||||
iter = _toAddedListeners.erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
const auto& children = target->getChildren();
|
||||
|
|
Loading…
Reference in New Issue