Opened 12 years ago

Closed 10 years ago

#3425 closed defect (fixed)

Creating menu items with NULL parent

Reported by: cwalther Owned by:
Priority: normal Milestone:
Component: GUI-all Version:
Keywords: wxMenuItem Cc: cwalther
Blocked By: Blocking:
Patch: yes


This code

wxMenuItem *item = new wxMenuItem(NULL, wxID_ANY,


triggers an assertion failure "menuitem should have a
menu" in wxMenuItemBase::wxMenuItemBase(...), whereas

wxMenu *menu = new wxMenu();
wxMenuItem *item = new wxMenuItem(menu, wxID_ANY,



seems to be perfectly legal - it's even done in
wxWidgets itself by wxMenuItemBase::DoRemove(wxMenuItem

Which one is right? I hope the second, because creating
parent-less menu items for adding or not adding them to
some menu later is useful. In that case, that assertion
should be removed, so that the first form can be used
as well.

Change History (3)

comment:1 Changed 10 years ago by wojdyr

  • Component set to GUI-all
  • Keywords wxMenuItem added

comment:2 Changed 10 years ago by wojdyr

  • Patch set
  • Status changed from new to confirmed

I think you are right.

--- src/common/menucmn.cpp      (revision 54304)
+++ src/common/menucmn.cpp      (working copy)
@@ -58,7 +58,7 @@
                                wxItemKind kind,
                                wxMenu *subMenu)
-    wxASSERT_MSG( parentMenu != NULL, wxT("menuitem should have a menu") );
+    // parent-less menuitem is legal -- the item can be later added to a menu
     m_parentMenu  = parentMenu;
     m_subMenu     = subMenu;

comment:3 Changed 10 years ago by vadz

  • Resolution set to fixed
  • Status changed from confirmed to closed

Ok, applied as r54329, thanks.

Note: See TracTickets for help on using tickets.