[bug] crash on menu item removal in running menu

[bug] crash on menu item removal in running menu
0.0 0


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:

  1. it’s a private member of CCMenu
  2. 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:

  1. redefine CCNode’s removeChild(…) and removeAllChildrenWithCleanup() methods in CCMenu so the m_pSelectedItem is checked and nullified if needed.
  2. define protected virtual onChildRemove() method (empty) in CCNode, call it in removal methods and redefine it in CCMenu.


Edit: Nevermind, I was overreleasing the menu. Everything’s behaving fine now.

I had leftover code for when I created the menu with New, but I’m no longer using new…
I’ve tested the object count and everything’s fine.