Thu, 23 Apr 2026 15:47:35 +0200
fix UiList creation without a UiContext
| application/main.c | file | annotate | diff | comparison | revisions | |
| ui/common/types.c | file | annotate | diff | comparison | revisions |
--- a/application/main.c Thu Apr 23 12:56:13 2026 +0200 +++ b/application/main.c Thu Apr 23 15:47:35 2026 +0200 @@ -956,6 +956,10 @@ threadpool = ui_threadpool_create(10); + // test + UiList *ls = ui_list_new(NULL, NULL); + ui_list_free(NULL, ls); + ui_main(); return (EXIT_SUCCESS);
--- a/ui/common/types.c Thu Apr 23 12:56:13 2026 +0200 +++ b/ui/common/types.c Thu Apr 23 15:47:35 2026 +0200 @@ -100,8 +100,9 @@ /* --------------------------- UiList --------------------------- */ void uic_ucx_list_init(UiContext *ctx, UiList *list, void *unused) { + const CxAllocator *a = ctx ? ctx->allocator : cxDefaultAllocator; list->destroy = uic_ucx_list_destroy; - list->data = cxArrayListCreate(ctx->mp->allocator, CX_STORE_POINTERS, 32); + list->data = cxArrayListCreate(a, CX_STORE_POINTERS, 32); list->first = ui_list_first; list->next = ui_list_next; list->get = ui_list_get; @@ -394,7 +395,7 @@ UiInteger* ui_int_new(UiContext *ctx, const char *name) { UiInteger *i = ui_malloc(ctx, sizeof(UiInteger)); memset(i, 0, sizeof(UiInteger)); - if(name) { + if(name && ctx) { uic_reg_var(ctx, name, UI_VAR_INTEGER, i); } return i; @@ -403,7 +404,7 @@ UiDouble* ui_double_new(UiContext *ctx, const char *name) { UiDouble *d = ui_malloc(ctx, sizeof(UiDouble)); memset(d, 0, sizeof(UiDouble)); - if(name) { + if(name && ctx) { uic_reg_var(ctx, name, UI_VAR_DOUBLE, d); } return d; @@ -419,7 +420,7 @@ UiString *s = ui_malloc(ctx, sizeof(UiString)); memset(s, 0, sizeof(UiString)); ui_set_destructor(s, (ui_destructor_func)string_destroy); - if(name) { + if(name && ctx) { uic_reg_var(ctx, name, UI_VAR_STRING, s); } return s; @@ -435,7 +436,7 @@ UiText *t = ui_malloc(ctx, sizeof(UiText)); memset(t, 0, sizeof(UiText)); ui_set_destructor(t, (ui_destructor_func)text_destroy); - if(name) { + if(name && ctx) { uic_reg_var(ctx, name, UI_VAR_TEXT, t); } return t; @@ -444,7 +445,7 @@ UiRange* ui_range_new(UiContext *ctx, const char *name) { UiRange *r = ui_malloc(ctx, sizeof(UiRange)); memset(r, 0, sizeof(UiRange)); - if(name) { + if(name && ctx) { uic_reg_var(ctx, name, UI_VAR_RANGE, r); } return r; @@ -459,8 +460,10 @@ UiGeneric* ui_generic_new(UiContext *ctx, const char *name) { UiGeneric *g = ui_malloc(ctx, sizeof(UiGeneric)); memset(g, 0, sizeof(UiGeneric)); - ui_set_destructor(g, (ui_destructor_func)generic_destroy); - if(name) { + if(ctx) { + ui_set_destructor(g, (ui_destructor_func)generic_destroy); + } + if(name && ctx) { uic_reg_var(ctx, name, UI_VAR_GENERIC, g); } return g;