mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-11 09:09:29 +00:00
ui_menu: guard select against empty menu
This commit is contained in:
@@ -344,7 +344,9 @@ bool MenuView::on_key(const KeyEvent key) {
|
|||||||
}
|
}
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case KeyEvent::Select:
|
case KeyEvent::Select:
|
||||||
if (menu_items[highlighted_item].on_select) {
|
// NB: a MenuView can legitimately be empty (e.g. after clear()) while
|
||||||
|
// still holding focus; indexing menu_items unchecked faults there.
|
||||||
|
if (highlighted_item < menu_items.size() && menu_items[highlighted_item].on_select) {
|
||||||
menu_items[highlighted_item].on_select(key);
|
menu_items[highlighted_item].on_select(key);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -364,7 +366,7 @@ bool MenuView::on_keyboard(const KeyboardEvent key) {
|
|||||||
if (key == '-') return set_highlighted(highlighted_item - 1);
|
if (key == '-') return set_highlighted(highlighted_item - 1);
|
||||||
if (key == '+') return set_highlighted(highlighted_item + 1);
|
if (key == '+') return set_highlighted(highlighted_item + 1);
|
||||||
if (key == 10) {
|
if (key == 10) {
|
||||||
if (menu_items[highlighted_item].on_select) {
|
if (highlighted_item < menu_items.size() && menu_items[highlighted_item].on_select) {
|
||||||
menu_items[highlighted_item].on_select(KeyEvent::Right);
|
menu_items[highlighted_item].on_select(KeyEvent::Right);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user