diff -r 1ce14068ef31 -r 294d5515583a ui/common/context.c --- a/ui/common/context.c Wed Oct 23 10:37:43 2024 +0200 +++ b/ui/common/context.c Wed Oct 23 17:40:45 2024 +0200 @@ -523,19 +523,28 @@ cxListDestroy(groups); } +size_t uic_group_array_size(const int *groups) { + int i; + for(i=0;groups[i] >= 0;i++) { } + return i; +} + void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, CxList *groups) { + uic_add_group_widget_i(ctx, widget, enable, cxListAt(groups, 0), cxListSize(groups)); +} + +void uic_add_group_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *groups, size_t numgroups) { const CxAllocator *a = ctx->allocator; UiGroupWidget gw; gw.widget = widget; gw.enable = enable; - gw.numgroups = cxListSize(groups); - gw.groups = cxCalloc(a, gw.numgroups, sizeof(int)); + gw.numgroups = numgroups; + gw.groups = cxCalloc(a, numgroups, sizeof(int)); // copy groups - int *intgroups = cxListAt(groups, 0); - if(intgroups) { - memcpy(gw.groups, intgroups, gw.numgroups * sizeof(int)); + if(groups) { + memcpy(gw.groups, groups, gw.numgroups * sizeof(int)); } cxListAdd(ctx->group_widgets, &gw); @@ -554,7 +563,7 @@ } void ui_free(UiContext *ctx, void *ptr) { - if(ctx) { + if(ctx && ptr) { cxFree(ctx->allocator, ptr); } }