Fix djui interactable crash when they get destroyed

This commit is contained in:
MysterD 2023-04-22 02:12:03 -07:00
parent 5b07d3b78c
commit afe7e28fb3
5 changed files with 18 additions and 8 deletions

View file

@ -1,5 +1,6 @@
#include <string.h>
#include "djui.h"
#include "djui_interactable.h"
////////////////
// properties //
@ -389,6 +390,13 @@ void djui_base_destroy(struct DjuiBase* base) {
base->interactable = NULL;
}
// remove from interactable variable
if (base == gDjuiHovered) { gDjuiHovered = NULL; }
if (base == gDjuiCursorDownOn) { gDjuiCursorDownOn = NULL; }
if (base == gInteractableFocus) { gInteractableFocus = NULL; }
if (base == gInteractableBinding) { gInteractableBinding = NULL; }
if (base == gInteractableMouseDown) { gInteractableMouseDown = NULL; }
// destroy this
base->destroy(base);
}

View file

@ -2,6 +2,7 @@
static void djui_checkbox_update_style(struct DjuiBase* base) {
struct DjuiCheckbox* checkbox = (struct DjuiCheckbox*)base;
if (!checkbox) { return; }
if (!checkbox->base.enabled) {
djui_base_set_border_color(&checkbox->rect->base, 93, 93, 93, 255);
djui_base_set_color(&checkbox->rect->base, 0, 0, 0, 0);

View file

@ -27,7 +27,7 @@ struct DjuiBase* gDjuiHovered = NULL;
struct DjuiBase* gDjuiCursorDownOn = NULL;
struct DjuiBase* gInteractableFocus = NULL;
struct DjuiBase* gInteractableBinding = NULL;
static struct DjuiBase* sMouseDown = NULL;
struct DjuiBase* gInteractableMouseDown = NULL;
bool gInteractableOverridePad = false;
OSContPad gInteractablePad = { 0 };
static OSContPad sLastInteractablePad = { 0 };
@ -399,17 +399,17 @@ void djui_interactable_update(void) {
} else if ((padButtons & PAD_BUTTON_A) || (mouseButtons & MOUSE_BUTTON_1)) {
// cursor down events
if (gDjuiHovered != NULL) {
sMouseDown = gDjuiHovered;
gInteractableMouseDown = gDjuiHovered;
gDjuiHovered = NULL;
djui_interactable_on_cursor_down_begin(sMouseDown, !mouseButtons);
djui_interactable_on_cursor_down_begin(gInteractableMouseDown, !mouseButtons);
} else {
djui_interactable_on_cursor_down(sMouseDown);
djui_interactable_on_cursor_down(gInteractableMouseDown);
}
} else {
// cursor up event
if (sMouseDown != NULL) {
djui_interactable_on_cursor_down_end(sMouseDown);
sMouseDown = NULL;
if (gInteractableMouseDown != NULL) {
djui_interactable_on_cursor_down_end(gInteractableMouseDown);
gInteractableMouseDown = NULL;
}
struct DjuiBase* lastHovered = gDjuiHovered;
gDjuiHovered = NULL;

View file

@ -46,6 +46,7 @@ extern struct DjuiBase* gDjuiHovered;
extern struct DjuiBase* gDjuiCursorDownOn;
extern struct DjuiBase* gInteractableFocus;
extern struct DjuiBase* gInteractableBinding;
extern struct DjuiBase* gInteractableMouseDown;
bool djui_interactable_is_binding(void);
void djui_interactable_set_binding(struct DjuiBase* base);

View file

@ -314,7 +314,7 @@ static bool gfx_texture_cache_lookup(int tile, struct TextureHashmapNode **n, co
hash = (hash >> HASH_SHIFT) & HASH_MASK;
struct TextureHashmapNode **node = &gfx_texture_cache.hashmap[hash];
while (*node != NULL && *node - gfx_texture_cache.pool < (int)gfx_texture_cache.pool_pos) {
while (node != NULL && *node != NULL && *node - gfx_texture_cache.pool < (int)gfx_texture_cache.pool_pos) {
if (CMPADDR((*node)->texture_addr, orig_addr) && (*node)->fmt == fmt && (*node)->siz == siz) {
gfx_rapi->select_texture(tile, (*node)->texture_id);
*n = *node;