CCMenu setHandlerPriority crash

CCMenu setHandlerPriority crash
0.0 0


Hello. i’m trying to set a lower touch priority to CCMenu but it crashes everytime becouse it is not registered as a touch listener. Why there is a such weird registration system? Why not let EVERY control derive from a single object which have a touch priority setter and getter? You’ve ignored my post( ) about button touch priority but it is only one logical solution. The code in the init method

CCMenuItemLabel * quit = CCMenuItemLabel::create(CCLabelTTF::create(TR("Cancel"), "FontName", 18), this, menu_selector(Settings::onCancel));
CCMenuItemLabel * save = CCMenuItemLabel::create(CCLabelTTF::create(TR("Save"), "FontName", 18), this, menu_selector(Settings::onSave));

CCMenu * menu = CCMenu::create(quit, save, NULL);
menu->setPosition(ccp( size.width / 2, size.height / 2 ));
menu->setHandlerPriority(kCCMenuHandlerPriority - 1); //Crash!

You are setting a touch priority from a constant and i think it is not a good solution to create user interface.


Hi, I don’t think this is an issue about touch priority.
If you want to call menu->setHandlerPriority(), please invoke it in SubLayer::onEnter() rather than in SubLayer::init(). :slight_smile:


Hi. Thanks for response. :slight_smile: I’m calling it not in the init now. I have popup layer with swallow touches and menu on it. I’m understand the reason of this crash and touch listener registration. But it would be nice to set a touch priority before a registering a new listener rather than set it from constant value kCCMenuHandlerPriority and change after adding to control list.


I’m trying to call menu~~>setHandlerPriority in Layer::onEnter as James suggested but it also crashes because in Layer::onEnter CCMenu is still not registered as a touch listener so where is the proper place to put menu~~>setHanderPriority() so it will not crash?