# HG changeset patch # User Olaf Wintermann # Date 1776621911 -7200 # Node ID d44c895e9ee98708673cc644251d967f4aaf3869 # Parent 655349c3021eb001afb335212352464958685e54 change ui_reg_destructor behavior: registered destructors are called before the context mempool is destroyed diff -r 655349c3021e -r d44c895e9ee9 ui/common/context.c --- a/ui/common/context.c Sun Apr 19 15:25:45 2026 +0200 +++ b/ui/common/context.c Sun Apr 19 20:05:11 2026 +0200 @@ -108,16 +108,23 @@ } UiEvent ev; - ev.window = NULL; + ev.obj = ctx->obj; + ev.window = ev.obj ? ev.obj->window : NULL; ev.document = document; - ev.obj = NULL; ev.eventdata = NULL; ev.eventdatatype = 0; ev.intval = 0; + ev.set = 0; if(ctx->close_callback) { ctx->close_callback(&ev, ctx->close_data); } + + CxIterator i = cxListIterator(ctx->destroy_handler); + cx_foreach(UiDestroyHandler *, h, i) { + h->destructor(h->data); + } + cxMempoolFree(ctx->mp); } @@ -552,14 +559,6 @@ ctx->close_data = udata; } -void ui_context_destroy(UiContext *ctx) { - CxIterator i = cxListIterator(ctx->destroy_handler); - cx_foreach(UiDestroyHandler *, h, i) { - h->destructor(h->data); - } - cxMempoolFree(ctx->mp); -} - UiContext* ui_context_parent(UiContext *ctx) { return ctx->parent; } @@ -730,7 +729,8 @@ } void ui_reg_destructor(UiContext *ctx, void *data, ui_destructor_func destr) { - cxMempoolRegister(ctx->mp, data, (cx_destructor_func)destr); + //cxMempoolRegister(ctx->mp, data, (cx_destructor_func)destr); + uic_context_add_destructor(ctx, destr, data); } void ui_set_destructor(void *mem, ui_destructor_func destr) { diff -r 655349c3021e -r d44c895e9ee9 ui/common/context.h --- a/ui/common/context.h Sun Apr 19 15:25:45 2026 +0200 +++ b/ui/common/context.h Sun Apr 19 20:05:11 2026 +0200 @@ -62,7 +62,7 @@ struct UiContext { UiContext *parent; UiObject *obj; - CxMempool *mp; + CxMempool *mp; const CxAllocator *allocator; CxList *destroy_handler; diff -r 655349c3021e -r d44c895e9ee9 ui/common/object.c --- a/ui/common/object.c Sun Apr 19 15:25:45 2026 +0200 +++ b/ui/common/object.c Sun Apr 19 20:05:11 2026 +0200 @@ -98,18 +98,8 @@ } void uic_object_destroy(UiObject *obj) { - if(obj->ctx->close_callback) { - UiEvent ev; - ev.window = obj->window; - ev.document = obj->ctx->document; - ev.obj = obj; - ev.eventdata = NULL; - ev.eventdatatype = 0; - ev.intval = 0; - obj->ctx->close_callback(&ev, obj->ctx->close_data); - } uic_object_destroyed(obj); - cxMempoolFree(obj->ctx->mp); + uic_context_destroy(obj->ctx, obj->ctx->document); } UiObject* uic_object_new_toplevel(void) { diff -r 655349c3021e -r d44c895e9ee9 ui/ui/toolkit.h --- a/ui/ui/toolkit.h Sun Apr 19 15:25:45 2026 +0200 +++ b/ui/ui/toolkit.h Sun Apr 19 20:05:11 2026 +0200 @@ -539,8 +539,6 @@ UIEXPORT void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata); -UIEXPORT void ui_context_destroy(UiContext *ctx); - UIEXPORT UiContext* ui_context_parent(UiContext *ctx); UIEXPORT void ui_object_ref(UiObject *obj);