From 9d358afe67cde6252ffdcfeaec0ebe69e4ecae18 Mon Sep 17 00:00:00 2001 From: VIFEX Date: Thu, 26 Jun 2025 16:50:49 +0800 Subject: [PATCH] fix(vg_lite): fix grad item not fully initialized (#8486) Signed-off-by: pengyiqiang Co-authored-by: pengyiqiang --- src/draw/vg_lite/lv_vg_lite_grad.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/draw/vg_lite/lv_vg_lite_grad.c b/src/draw/vg_lite/lv_vg_lite_grad.c index dece04f08b..02d7ef735b 100644 --- a/src/draw/vg_lite/lv_vg_lite_grad.c +++ b/src/draw/vg_lite/lv_vg_lite_grad.c @@ -423,25 +423,27 @@ static grad_item_t * grad_item_pool_alloc(lv_vg_lite_grad_ctx_t * ctx, grad_type grad_item_t * item = lv_ll_get_head(&ctx->item_pool); - /* Always get free nodes from the head */ + /* Try to obtain a free node from the head */ if(item && item->type == GRAD_TYPE_FREE) { - item->type = type; lv_ll_move_before(&ctx->item_pool, item, NULL); LV_LOG_TRACE("reuse item: %p, type: %d", (void *)item, type); - return item; - } - - item = lv_ll_ins_tail(&ctx->item_pool); - LV_ASSERT_MALLOC(item); - if(!item) { - LV_LOG_ERROR("alloc grad item failed"); - return NULL; + } + else { + /* Allocate a new node if the pool is empty or all nodes are in use */ + item = lv_ll_ins_tail(&ctx->item_pool); + LV_ASSERT_MALLOC(item); + if(!item) { + LV_LOG_ERROR("alloc grad item failed"); + return NULL; + } + + LV_LOG_TRACE("alloc new item: %p, type: %d, pool size: %" LV_PRIu32, + (void *)item, type, lv_ll_get_len(&ctx->item_pool)); } + lv_memzero(item, sizeof(grad_item_t)); item->ctx = ctx; item->type = type; - LV_LOG_TRACE("alloc new item: %p, type: %d, pool size: %" LV_PRIu32, - (void *)item, type, lv_ll_get_len(&ctx->item_pool)); return item; }