Hi! Just found a bug, here’s a short description:
In my project I modify a list of MenuItem children nodes in Menu. The nodes are added and deleted by MenuItem handlers. The problem is sometimes I get crash when removing a node from menu. This happens because of m_pSelectedItem member in CCMenu; there’s a chance of getting it point to invalid (removed and even destroyed) node. The answer “just don’t do it” isn’t corrent following to these reasons:
- it’s a private member of CCMenu
- there’s a way to get it invalid using CCMenu public interface
So it’s a bug and I can suggest 2 ways to fix it:
- redefine CCNode’s removeChild(…) and removeAllChildrenWithCleanup() methods in CCMenu so the m_pSelectedItem is checked and nullified if needed.
- define protected virtual onChildRemove() method (empty) in CCNode, call it in removal methods and redefine it in CCMenu.