Fix browser navigation crashes

This commit is contained in:
jacqueline
2023-07-13 09:37:32 +10:00
parent 8eabeedbb9
commit 2dc700b12f
2 changed files with 8 additions and 11 deletions
+3 -1
View File
@@ -25,8 +25,10 @@ class Screen {
Screen() : root_(lv_obj_create(NULL)), group_(lv_group_create()) {} Screen() : root_(lv_obj_create(NULL)), group_(lv_group_create()) {}
virtual ~Screen() { 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_group_del(group_);
lv_obj_del(root_);
} }
/* /*
+5 -10
View File
@@ -307,18 +307,13 @@ auto TrackBrowser::GetRecordByIndex(std::size_t index)
} }
ESP_LOGI(kTag, "total tracks %u, getting index %u", total_tracks, 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_) { for (const auto& page : current_pages_) {
if (index > current_index + page->values().size()) { for (int i = 0; i < page->values().size(); i++) {
current_index += page->values().size(); if (index == 0) {
continue; return page->values().at(i);
}
index--;
} }
if (index < current_index) {
// uhhh
break;
}
std::size_t index_in_page = index - current_index;
return page->values().at(index_in_page);
} }
return {}; return {};
} }