Merge pull request #4852 from dumganhar/iss3579-lua-bugtest914-crash

closed #3579: TestLua->BugsTest->bug914 crashes if clicking 'reset' button all the time.
This commit is contained in:
James Chen 2014-01-03 18:51:16 -08:00
commit f3eb21e748
5 changed files with 54 additions and 61 deletions

View File

@ -279,11 +279,10 @@ void EventDispatcher::associateNodeAndEventListener(Node* node, EventListener* l
else
{
listeners = new std::vector<EventListener*>();
_nodeListenersMap.insert(std::make_pair(node, listeners));
}
listeners->push_back(listener);
_nodeListenersMap.insert(std::make_pair(node, listeners));
}
void EventDispatcher::dissociateNodeAndEventListener(Node* node, EventListener* listener)
@ -311,29 +310,7 @@ void EventDispatcher::addEventListener(EventListener* listener)
{
if (_inDispatch == 0)
{
EventListenerVector* listenerList = nullptr;
auto iter = _listeners.find(listener->getListenerID());
if (iter == _listeners.end())
{
listenerList = new EventListenerVector();
_listeners.insert(std::make_pair(listener->getListenerID(), listenerList));
}
else
{
listenerList = iter->second;
}
listenerList->push_back(listener);
if (listener->getFixedPriority() == 0)
{
setDirty(listener->getListenerID(), DirtyFlag::SCENE_GRAPH_PRIORITY);
}
else
{
setDirty(listener->getListenerID(), DirtyFlag::FIXED_PRITORY);
}
forceAddEventListener(listener);
}
else
{
@ -343,6 +320,44 @@ void EventDispatcher::addEventListener(EventListener* listener)
listener->retain();
}
void EventDispatcher::forceAddEventListener(EventListener* listener)
{
EventListenerVector* listeners = nullptr;
EventListener::ListenerID listenerID = listener->getListenerID();
auto itr = _listeners.find(listenerID);
if (itr == _listeners.end())
{
listeners = new EventListenerVector();
_listeners.insert(std::make_pair(listenerID, listeners));
}
else
{
listeners = itr->second;
}
listeners->push_back(listener);
if (listener->getFixedPriority() == 0)
{
setDirty(listenerID, DirtyFlag::SCENE_GRAPH_PRIORITY);
auto node = listener->getSceneGraphPriority();
CCASSERT(node != nullptr, "Invalid scene graph priority!");
associateNodeAndEventListener(node, listener);
if (node->isRunning())
{
resumeTarget(node);
}
}
else
{
setDirty(listenerID, DirtyFlag::FIXED_PRITORY);
}
}
void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* listener, Node* node)
{
CCASSERT(listener && node, "Invalid parameters.");
@ -356,13 +371,6 @@ void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* list
listener->setRegistered(true);
addEventListener(listener);
associateNodeAndEventListener(node, listener);
if (node->isRunning())
{
resumeTarget(node);
}
}
void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener, int fixedPriority)
@ -873,33 +881,9 @@ void EventDispatcher::updateListeners(Event* event)
if (!_toAddedListeners.empty())
{
EventListenerVector* listeners = nullptr;
for (auto& listener : _toAddedListeners)
{
EventListener::ListenerID listenerID = listener->getListenerID();
auto itr = _listeners.find(listenerID);
if (itr == _listeners.end())
{
listeners = new EventListenerVector();
_listeners.insert(std::make_pair(listenerID, listeners));
}
else
{
listeners = itr->second;
}
listeners->push_back(listener);
if (listener->getFixedPriority() == 0)
{
setDirty(listenerID, DirtyFlag::SCENE_GRAPH_PRIORITY);
}
else
{
setDirty(listenerID, DirtyFlag::FIXED_PRITORY);
}
forceAddEventListener(listener);
}
_toAddedListeners.clear();
}

View File

@ -155,9 +155,18 @@ protected:
ssize_t _gt0Index;
};
/** Adds event listener with item */
/** Adds an event listener with item
* @note if it is dispatching event, the added operation will be delayed to the end of current dispatch
* @see forceAddEventListener
*/
void addEventListener(EventListener* listener);
/** Force adding an event listener
* @note force add an event listener which will ignore whether it's in dispatching.
* @see addEventListener
*/
void forceAddEventListener(EventListener* listener);
/** Gets event the listener list for the event listener type. */
EventListenerVector* getListeners(const EventListener::ListenerID& listenerID);

View File

@ -1 +1 @@
9f5dda004e2659caf1fc9f9032e7b386754c7200
16af4ad046f4db00af7a229d89c406054d8616c3

View File

@ -1 +1 @@
31ce7e2d174b3b02eb3a30cbc999f1302c70b685
f0ef8eb2f398001c933c2608c1eb219db7deaebf

View File

@ -1,4 +1,4 @@
require "Cocos2dStudio"
require "CocoStudio"
local TMoveBy = class("TMoveBy")
TMoveBy._tag = -1