UI: Fix crash on item select with hidden items.

Because we can't assume the number is an index into the views, when some
of those views weren't created.
This commit is contained in:
Unknown W. Brackets 2017-04-29 13:04:28 -07:00
parent 9ea7281b3c
commit de3c4fe111

View File

@ -1293,7 +1293,7 @@ void ListView::CreateAllItems() {
// Let's not be clever yet, we'll just create them all up front and add them all in.
for (int i = 0; i < adaptor_->GetNumItems(); i++) {
if (hidden_.find(i) == hidden_.end()) {
View * v = linLayout_->Add(adaptor_->CreateItemView(i));
View *v = linLayout_->Add(adaptor_->CreateItemView(i));
adaptor_->AddEventCallback(v, std::bind(&ListView::OnItemCallback, this, i, std::placeholders::_1));
}
}
@ -1315,7 +1315,7 @@ EventReturn ListView::OnItemCallback(int num, EventParams &e) {
OnChoice.Trigger(ev);
CreateAllItems();
if (focused)
SetFocusedView(linLayout_->GetViewByIndex(num));
SetFocusedView(e.v);
return EVENT_DONE;
}