Fix for djui_panel_find_first_interactable returning garbage if the loop aborts. (#339)

This commit is contained in:
Prince Frizzy 2023-04-09 07:52:02 -04:00 committed by GitHub
parent f7a3e5f0a6
commit f010caeb4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@
#include "djui_panel_main.h" #include "djui_panel_main.h"
#include "djui_panel_pause.h" #include "djui_panel_pause.h"
#include "djui_panel_join_message.h" #include "djui_panel_join_message.h"
#include "src/pc/debuglog.h"
#include "src/pc/utils/misc.h" #include "src/pc/utils/misc.h"
#include "sounds.h" #include "sounds.h"
#include "audio/external.h" #include "audio/external.h"
@ -17,14 +18,19 @@ 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) {
while (child) { struct DjuiBaseChild *i = child;
if (child->base->interactable && child->base->interactable->enabled) { while (i) {
return child->base; if (i->base->interactable && i->base->interactable->enabled) {
return i->base;
} }
struct DjuiBase* check = djui_panel_find_first_interactable(child->base->child); struct DjuiBase* check = djui_panel_find_first_interactable(i->base->child);
if (check) { return check; } if (check) { return check; }
child = child->next; i = i->next;
} }
// If we didn't find anything at all. Return NULL.
LOG_ERROR("Failed to find a interactable for child %p.", child);
return NULL;
} }
struct DjuiPanel* djui_panel_add(struct DjuiBase* caller, struct DjuiThreePanel* threePanel, struct DjuiBase* defaultElementBase) { struct DjuiPanel* djui_panel_add(struct DjuiBase* caller, struct DjuiThreePanel* threePanel, struct DjuiBase* defaultElementBase) {