From 02a934ed97e207922fac0e3ed4fc6bd8893ef59e Mon Sep 17 00:00:00 2001 From: Christoph Heinrich Date: Tue, 25 Jul 2023 23:46:37 +0200 Subject: [PATCH] fix: crash when a script menu update renders selected index unavailable --- scripts/uosc/elements/Menu.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/uosc/elements/Menu.lua b/scripts/uosc/elements/Menu.lua index 76bbc7ce..e686521f 100644 --- a/scripts/uosc/elements/Menu.lua +++ b/scripts/uosc/elements/Menu.lua @@ -186,6 +186,10 @@ function Menu:update(data) local old_menu = self.by_id[menu.is_root and '__root__' or menu.id] if old_menu then table_assign(menu, old_menu, {'selected_index', 'scroll_y', 'fling'}) end + if menu.selected_index then + menu.selected_index = clamp(1, menu.selected_index, #menu.items) + end + new_all[#new_all + 1] = menu new_by_id[menu.is_root and '__root__' or menu.id] = menu end