diff --git a/cocos2dx/include/CCMutableArray.h b/cocos2dx/include/CCMutableArray.h index 49d0cd7e8d..ccfab68c55 100644 --- a/cocos2dx/include/CCMutableArray.h +++ b/cocos2dx/include/CCMutableArray.h @@ -325,6 +325,22 @@ public: return m_array.rbegin(); } + CCMutableArrayIterator getLastValidIterator(void) + { + CCMutableArrayIterator iter; + CCMutableArrayIterator ret; + for (iter = m_array.begin(); iter != m_array.end(); ++iter) + { + ret = iter; + if (! (*iter)) + { + break; + } + } + + return ret; + } + /* * end is a keyword of lua, so should use other name * to export to lua diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp index 9b48f529b6..06df570b20 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp @@ -264,7 +264,7 @@ CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate) void CCTouchDispatcher::rearrangeHandlers(CCMutableArray *pArray) { - std::sort(pArray->begin(), pArray->end(), less); + std::sort(pArray->begin(), pArray->getLastValidIterator(), less); } void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)