summaryrefslogtreecommitdiff
path: root/src/static-ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/static-ui.cpp')
-rw-r--r--src/static-ui.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/static-ui.cpp b/src/static-ui.cpp
index 6858905..882a3dc 100644
--- a/src/static-ui.cpp
+++ b/src/static-ui.cpp
@@ -760,7 +760,7 @@ void pke_ui_tick(double delta) {
}
void pke_ui_teardown_box_recursive(pke_ui_box *box, uint8_t depth) {
- FontRender *fr;
+ FontRender *fr = nullptr;
pke_ui_graphics_bindings_texture *bindings = nullptr;
for (pke_ui_box_count_T i = 0; i < box->internal.h_children; ++i) {
pke_ui_teardown_box_recursive(box->internal.children[i], depth + 1);
@@ -771,20 +771,10 @@ void pke_ui_teardown_box_recursive(pke_ui_box *box, uint8_t depth) {
if (box->type_data != nullptr) {
switch (box->type) {
case PKE_UI_BOX_TYPE_TEXT:
- // 2025-09-16 JCB
- // If correctly parented, this is unnecessary, but serialization does
- // not construct text boxes in this way.
- // Handle to avoid memory leaks.
fr = FontType_GetFontRender(box->type_data->text.font_type_render);
- if (fr != nullptr && fr->parentHandle != box->handle) {
- FontType_RemoveStringRender(box->type_data->text.font_type_render);
- }
break;
case PKE_UI_BOX_TYPE_BUTTON_TEXT:
fr = FontType_GetFontRender(box->type_data->button_text.font_type_render);
- if (fr != nullptr && fr->parentHandle != box->handle) {
- FontType_RemoveStringRender(box->type_data->button_text.font_type_render);
- }
break;
case PKE_UI_BOX_TYPE_BUTTON_IMAGE:
if (box->type_data->button_image.gr_binds_bkt_arr_handle != pk_bkt_arr_handle_MAX) {
@@ -824,11 +814,19 @@ void pke_ui_teardown_box_recursive(pke_ui_box *box, uint8_t depth) {
box->type_data = nullptr;
}
pk_arr_append_t<pke_ui_box*>(&pke_ui_master.boxes_to_delete, box);
+ // 2025-09-16 JCB
+ // If correctly parented, this is unnecessary, but de/serialization does
+ // not construct text boxes in this way.
+ // Handle explicitly to avoid memory leaks.
+ if (fr != nullptr && fr->parentHandle != box->handle) {
+ FontType_RemoveStringRender(FontTypeRender{fr->font_type_handle, fr->font_render_handle});
+ }
/* 2025-09-25 JCB HACK
* I'd like this to be more elegant, this seems hacky.
* We need to skip the first (the one we marked for removal).
* If we are manually managing child boxes (like deleting in the editor),
* then this can get called when depth > 0 but the box is already marked.
+ * The box at depth==0 is already marked, so only mark children.
*/
if (depth != 0 && box->isMarkedForRemoval == false) {
ECS_MarkForRemoval(box);