From 2dc700b12f26109d987ad22f530e39d165025656 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 13 Jul 2023 09:37:32 +1000 Subject: [PATCH] Fix browser navigation crashes --- src/ui/include/screen.hpp | 4 +++- src/ui/screen_track_browser.cpp | 15 +++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ui/include/screen.hpp b/src/ui/include/screen.hpp index 13b92a09..c6b2f137 100644 --- a/src/ui/include/screen.hpp +++ b/src/ui/include/screen.hpp @@ -25,8 +25,10 @@ class Screen { Screen() : root_(lv_obj_create(NULL)), group_(lv_group_create()) {} virtual ~Screen() { - lv_obj_del(root_); + // The group *must* be deleted first. Otherwise, focus events will be + // generated whilst deleting the object tree, which causes a big mess. lv_group_del(group_); + lv_obj_del(root_); } /* diff --git a/src/ui/screen_track_browser.cpp b/src/ui/screen_track_browser.cpp index 8f8321d7..86140558 100644 --- a/src/ui/screen_track_browser.cpp +++ b/src/ui/screen_track_browser.cpp @@ -307,18 +307,13 @@ auto TrackBrowser::GetRecordByIndex(std::size_t index) } ESP_LOGI(kTag, "total tracks %u, getting index %u", total_tracks, index); - std::size_t current_index = 0; for (const auto& page : current_pages_) { - if (index > current_index + page->values().size()) { - current_index += page->values().size(); - continue; - } - if (index < current_index) { - // uhhh - break; + for (int i = 0; i < page->values().size(); i++) { + if (index == 0) { + return page->values().at(i); + } + index--; } - std::size_t index_in_page = index - current_index; - return page->values().at(index_in_page); } return {}; }