Fix selectionbox crash when out of range

This commit is contained in:
MysterD 2023-04-09 17:25:45 -07:00
parent f010caeb4b
commit 2b5dea60b0
2 changed files with 10 additions and 7 deletions

View file

@ -18,16 +18,15 @@ bool djui_panel_is_active(void) {
} }
struct DjuiBase* djui_panel_find_first_interactable(struct DjuiBaseChild* child) { struct DjuiBase* djui_panel_find_first_interactable(struct DjuiBaseChild* child) {
struct DjuiBaseChild *i = child; while (child) {
while (i) { if (child->base->interactable && child->base->interactable->enabled) {
if (i->base->interactable && i->base->interactable->enabled) { return child->base;
return i->base;
} }
struct DjuiBase* check = djui_panel_find_first_interactable(i->base->child); struct DjuiBase* check = djui_panel_find_first_interactable(child->base->child);
if (check) { return check; } if (check) { return check; }
i = i->next; child = child->next;
} }
// If we didn't find anything at all. Return NULL. // If we didn't find anything at all. Return NULL.
LOG_ERROR("Failed to find a interactable for child %p.", child); LOG_ERROR("Failed to find a interactable for child %p.", child);
return NULL; return NULL;

View file

@ -76,6 +76,10 @@ struct DjuiSelectionbox* djui_selectionbox_create(struct DjuiBase* parent, const
struct DjuiSelectionbox* selectionbox = calloc(1, sizeof(struct DjuiSelectionbox)); struct DjuiSelectionbox* selectionbox = calloc(1, sizeof(struct DjuiSelectionbox));
struct DjuiBase* base = &selectionbox->base; struct DjuiBase* base = &selectionbox->base;
if (*value >= choiceCount) {
*value = choiceCount - 1;
}
selectionbox->value = value; selectionbox->value = value;
selectionbox->choices = calloc(choiceCount, sizeof(char*)); selectionbox->choices = calloc(choiceCount, sizeof(char*));
for (int i = 0; i < choiceCount; i++) { for (int i = 0; i < choiceCount; i++) {