зеркало из https://github.com/microsoft/cocos2d-x.git
Merge pull request #5575 from dumganhar/iss4286-event-crash
closed #4286: 'EventDispatcherTest/Issue 4129' crashes on Windows.
This commit is contained in:
Коммит
87b657b5bb
|
@ -882,6 +882,8 @@ void EventDispatcher::dispatchTouchEvent(EventTouch* event)
|
|||
|
||||
void EventDispatcher::updateListeners(Event* event)
|
||||
{
|
||||
CCASSERT(_inDispatch > 0, "If program goes here, there should be event in dispatch.");
|
||||
|
||||
auto onUpdateListeners = [this](const EventListener::ListenerID& listenerID)
|
||||
{
|
||||
auto listenersIter = _listenerMap.find(listenerID);
|
||||
|
@ -889,6 +891,7 @@ void EventDispatcher::updateListeners(Event* event)
|
|||
return;
|
||||
|
||||
auto listeners = listenersIter->second;
|
||||
|
||||
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
|
||||
auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners();
|
||||
|
||||
|
@ -935,15 +938,9 @@ void EventDispatcher::updateListeners(Event* event)
|
|||
{
|
||||
listeners->clearFixedListeners();
|
||||
}
|
||||
|
||||
if (listenersIter->second->empty())
|
||||
{
|
||||
_priorityDirtyFlagMap.erase(listenersIter->first);
|
||||
delete listenersIter->second;
|
||||
_listenerMap.erase(listenersIter);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (event->getType() == Event::Type::TOUCH)
|
||||
{
|
||||
onUpdateListeners(EventListenerTouchOneByOne::LISTENER_ID);
|
||||
|
@ -954,6 +951,24 @@ void EventDispatcher::updateListeners(Event* event)
|
|||
onUpdateListeners(__getListenerID(event));
|
||||
}
|
||||
|
||||
if (_inDispatch > 1)
|
||||
return;
|
||||
|
||||
CCASSERT(_inDispatch == 1, "_inDispatch should be 1 here.");
|
||||
|
||||
for (auto iter = _listenerMap.begin(); iter != _listenerMap.end();)
|
||||
{
|
||||
if (iter->second->empty())
|
||||
{
|
||||
_priorityDirtyFlagMap.erase(iter->first);
|
||||
delete iter->second;
|
||||
iter = _listenerMap.erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_toAddedListeners.empty())
|
||||
{
|
||||
|
|
|
@ -1182,6 +1182,7 @@ Issue4129::Issue4129()
|
|||
|
||||
// After test, remove it.
|
||||
_eventDispatcher->removeEventListener(_customlistener);
|
||||
_customlistener = nullptr;
|
||||
|
||||
_bugFixed = true;
|
||||
});
|
||||
|
@ -1219,9 +1220,12 @@ Issue4129::Issue4129()
|
|||
}
|
||||
|
||||
Issue4129::~Issue4129()
|
||||
{
|
||||
if (_customlistener)
|
||||
{
|
||||
_eventDispatcher->removeEventListener(_customlistener);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Issue4129::title() const
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче