Fix crash with cursor use after free

This commit is contained in:
EmeraldLockdown 2026-03-10 15:04:44 -05:00
parent 65dbb835e7
commit eb6ef89b76
3 changed files with 11 additions and 4 deletions

View file

@ -353,6 +353,11 @@ void djui_base_destroy(struct DjuiBase* base) {
gInteractableBinding = NULL;
}
// remove input controlled base
if (gInputControlledBase == base) {
gInputControlledBase = NULL;
}
// remove myself from parent's linked list
if (base->parent != NULL) {
struct DjuiBaseChild* child = base->parent->child;

View file

@ -12,7 +12,7 @@ extern ALIGNED8 u8 gd_texture_hand_closed[];
struct DjuiImage* sMouseCursor = NULL;
static bool sCursorMouseControlled = false;
static struct DjuiBase* sInputControlledBase = NULL;
struct DjuiBase* gInputControlledBase = NULL;
static f32 sSavedMouseX = 0;
static f32 sSavedMouseY = 0;
@ -55,7 +55,7 @@ static void djui_cursor_base_hover_location(struct DjuiBase* base, f32* x, f32*
void djui_cursor_input_controlled_center(struct DjuiBase* base) {
if (!sCursorMouseControlled && (!base || (base && base->interactable && base->interactable->enabled))) {
sInputControlledBase = base;
gInputControlledBase = base;
djui_cursor_set_visible(base != NULL);
}
}
@ -147,8 +147,8 @@ static void djui_cursor_update_position(void) {
if (sCursorMouseControlled) {
gCursorX = mouse_window_x / djui_gfx_get_scale();
gCursorY = mouse_window_y / djui_gfx_get_scale();
} else if (sInputControlledBase != NULL) {
djui_cursor_base_hover_location(sInputControlledBase, &gCursorX, &gCursorY);
} else if (gInputControlledBase != NULL) {
djui_cursor_base_hover_location(gInputControlledBase, &gCursorX, &gCursorY);
}
// set cursor position

View file

@ -5,6 +5,8 @@
extern f32 gCursorX;
extern f32 gCursorY;
extern struct DjuiBase* gInputControlledBase;
void djui_cursor_set_visible(bool visible);
bool djui_cursor_inside_base(struct DjuiBase* base);
void djui_cursor_input_controlled_center(struct DjuiBase* base);