mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6169 from dumganhar/iss4710-eventdispatcher-crash
closed #4710: [win32] Crash in EventDispatcher if game starts up with mouse moving frequently
This commit is contained in:
commit
5df765ef0c
|
@ -393,7 +393,10 @@ void Director::setOpenGLView(GLView *openGLView)
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
// _touchDispatcher->setDispatchEvents(true);
|
if (_eventDispatcher)
|
||||||
|
{
|
||||||
|
_eventDispatcher->setEnabled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,9 +750,11 @@ void Director::purgeDirector()
|
||||||
// cleanup scheduler
|
// cleanup scheduler
|
||||||
getScheduler()->unscheduleAll();
|
getScheduler()->unscheduleAll();
|
||||||
|
|
||||||
// don't release the event handlers
|
// Disable event dispatching
|
||||||
// They are needed in case the director is run again
|
if (_eventDispatcher)
|
||||||
// _touchDispatcher->removeAllDelegates();
|
{
|
||||||
|
_eventDispatcher->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (_runningScene)
|
if (_runningScene)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include "CCEventListenerKeyboard.h"
|
#include "CCEventListenerKeyboard.h"
|
||||||
#include "CCEventListenerCustom.h"
|
#include "CCEventListenerCustom.h"
|
||||||
|
|
||||||
#include "CCNode.h"
|
#include "CCScene.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCEventType.h"
|
#include "CCEventType.h"
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ void EventDispatcher::EventListenerVector::clear()
|
||||||
|
|
||||||
EventDispatcher::EventDispatcher()
|
EventDispatcher::EventDispatcher()
|
||||||
: _inDispatch(0)
|
: _inDispatch(0)
|
||||||
, _isEnabled(true)
|
, _isEnabled(false)
|
||||||
, _nodePriorityIndex(0)
|
, _nodePriorityIndex(0)
|
||||||
{
|
{
|
||||||
_toAddedListeners.reserve(50);
|
_toAddedListeners.reserve(50);
|
||||||
|
@ -1125,6 +1125,9 @@ void EventDispatcher::sortEventListeners(const EventListener::ListenerID& listen
|
||||||
|
|
||||||
if (dirtyFlag != DirtyFlag::NONE)
|
if (dirtyFlag != DirtyFlag::NONE)
|
||||||
{
|
{
|
||||||
|
// Clear the dirty flag first, if `rootNode` is nullptr, then set its dirty flag of scene graph priority
|
||||||
|
dirtyIter->second = DirtyFlag::NONE;
|
||||||
|
|
||||||
if ((int)dirtyFlag & (int)DirtyFlag::FIXED_PRIORITY)
|
if ((int)dirtyFlag & (int)DirtyFlag::FIXED_PRIORITY)
|
||||||
{
|
{
|
||||||
sortEventListenersOfFixedPriority(listenerID);
|
sortEventListenersOfFixedPriority(listenerID);
|
||||||
|
@ -1132,14 +1135,20 @@ void EventDispatcher::sortEventListeners(const EventListener::ListenerID& listen
|
||||||
|
|
||||||
if ((int)dirtyFlag & (int)DirtyFlag::SCENE_GRAPH_PRIORITY)
|
if ((int)dirtyFlag & (int)DirtyFlag::SCENE_GRAPH_PRIORITY)
|
||||||
{
|
{
|
||||||
sortEventListenersOfSceneGraphPriority(listenerID);
|
auto rootNode = Director::getInstance()->getRunningScene();
|
||||||
|
if (rootNode)
|
||||||
|
{
|
||||||
|
sortEventListenersOfSceneGraphPriority(listenerID, rootNode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dirtyIter->second = DirtyFlag::SCENE_GRAPH_PRIORITY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyIter->second = DirtyFlag::NONE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID)
|
void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID, Node* rootNode)
|
||||||
{
|
{
|
||||||
auto listeners = getListeners(listenerID);
|
auto listeners = getListeners(listenerID);
|
||||||
|
|
||||||
|
@ -1150,7 +1159,6 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener
|
||||||
if (sceneGraphListeners == nullptr)
|
if (sceneGraphListeners == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Node* rootNode = (Node*)Director::getInstance()->getRunningScene();
|
|
||||||
// Reset priority index
|
// Reset priority index
|
||||||
_nodePriorityIndex = 0;
|
_nodePriorityIndex = 0;
|
||||||
_nodePriorityMap.clear();
|
_nodePriorityMap.clear();
|
||||||
|
@ -1158,7 +1166,6 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener
|
||||||
visitTarget(rootNode, true);
|
visitTarget(rootNode, true);
|
||||||
|
|
||||||
// After sort: priority < 0, > 0
|
// After sort: priority < 0, > 0
|
||||||
|
|
||||||
std::sort(sceneGraphListeners->begin(), sceneGraphListeners->end(), [this](const EventListener* l1, const EventListener* l2) {
|
std::sort(sceneGraphListeners->begin(), sceneGraphListeners->end(), [this](const EventListener* l1, const EventListener* l2) {
|
||||||
return _nodePriorityMap[l1->getSceneGraphPriority()] > _nodePriorityMap[l2->getSceneGraphPriority()];
|
return _nodePriorityMap[l1->getSceneGraphPriority()] > _nodePriorityMap[l2->getSceneGraphPriority()];
|
||||||
});
|
});
|
||||||
|
@ -1351,7 +1358,6 @@ void EventDispatcher::setEnabled(bool isEnabled)
|
||||||
_isEnabled = isEnabled;
|
_isEnabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EventDispatcher::isEnabled() const
|
bool EventDispatcher::isEnabled() const
|
||||||
{
|
{
|
||||||
return _isEnabled;
|
return _isEnabled;
|
||||||
|
|
|
@ -207,7 +207,7 @@ protected:
|
||||||
void sortEventListeners(const EventListener::ListenerID& listenerID);
|
void sortEventListeners(const EventListener::ListenerID& listenerID);
|
||||||
|
|
||||||
/** Sorts the listeners of specified type by scene graph priority */
|
/** Sorts the listeners of specified type by scene graph priority */
|
||||||
void sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID);
|
void sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID, Node* rootNode);
|
||||||
|
|
||||||
/** Sorts the listeners of specified type by fixed priority */
|
/** Sorts the listeners of specified type by fixed priority */
|
||||||
void sortEventListenersOfFixedPriority(const EventListener::ListenerID& listenerID);
|
void sortEventListenersOfFixedPriority(const EventListener::ListenerID& listenerID);
|
||||||
|
|
Loading…
Reference in New Issue