ps. wenbin wang has feedback to me…thank you for your help!!!As follows…
pDispatcher~~>findHandler return NULL is because CCMenu::registerWithTouchDispatcher hasn’t be called yet.
CCMenu::registerWithTouchDispatcher is called by the onEnter function, after that, the TouchDispatcher will add a handler to the CCMenu, and pDispatcher~~>findHandler(this) will return the handler instead of NULL. See the implement above.
So In CCMenu::setHandlerPriority(int newPriority), firstly I check if the handler has been add by pDispatcher~~>findHandler. If it is, call pDispatcher~~>setPriority(newPriority, this); to modify the touchPriority. Otherwise, just store the priority in member m_handlerPriority and wait CCMenu::registerWithTouchDispatcher() to handle it.
I think most of the devs will do the initial jobs on init(); function (or even in constructor) including the touch priorities of the menus.
This kind of re-ordering touch priorities are crucial for making Popups or Dialogs which can be ‘stacked’ over themselves.
I really don’t like modifying the original code INSIDE the LIBRARY itself, but I had to modify it.
I hope in the next version this changes committed to the main repository.
Yes, I also think that setHandlerPriority should store given priority in a member veriable to use it in registerWithTouchDispatcher if handler is not currently registered. In current cocos2d-x version I can’t see any proper place to put setHandlerPriority because it crashes even if you put it into your Layer::onEnter() (as I said here: http://www.cocos2d-x.org/boards/6/topics/12661).