From 03b96ef737cb4592bc545271bddb8c17e8584d34 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sun, 27 Mar 2016 09:06:06 -0700 Subject: [PATCH] Fix crash on Mac on 2nd click of Port menu --- gui.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gui.cpp b/gui.cpp index 65fe054..78e7df6 100644 --- a/gui.cpp +++ b/gui.cpp @@ -319,12 +319,9 @@ void MyMenu::OnShowPortList(wxMenuEvent &event) menu = event.GetMenu(); //printf("OnShowPortList, %s\n", (const char *)menu->GetTitle()); if (menu != port_menu) return; - - wxMenuItemList old_items = menu->GetMenuItems(); - num = old_items.GetCount(); - for (int i = old_items.GetCount() - 1; i >= 0; i--) { - menu->Delete(old_items[i]); - } + while (menu->GetMenuItemCount() > 0) { + menu->Delete(menu->GetMenuItems()[0]); + } menu->AppendRadioItem(9000, " (none)"); wxArrayString list = serial_port_list(); num = list.GetCount(); @@ -338,6 +335,7 @@ void MyMenu::OnShowPortList(wxMenuEvent &event) } } if (!any) menu->Check(9000, true); + menu->UpdateUI(); } void MyMenu::OnHighlight(wxMenuEvent &event)