How to change periodically a label text?

Hi!

I’m facing an issue that I don’t understand. I’m using LVGL with the ESP-IDF on an ESP32-S3 DevKitC 1. Sorry for my english I’m not a native.

What I did

I created a simple rectangle that has a grid layout. Inside this grid I put a label with a time string inside :

    lv_obj_t* time_txt = lv_label_create(header);
    time_t result = time(NULL);
    struct tm *tm_info = localtime(&result);

    char buffer[32];
    strftime(buffer, sizeof(buffer), "%H:%M:%S %d/%m/%Y", tm_info);
    lv_label_set_text(time_txt, buffer);
    lv_obj_set_grid_cell(time_txt, LV_GRID_ALIGN_CENTER, 4, 6, LV_GRID_ALIGN_CENTER, 0, 1);

It works well, but I want to create a periodic callback to change it every second (approximately, it’s not important)

lv_timer_create(update_time_txt, 1000, time_txt); // Call this callback every one second

Alright, now in my callback function I have these lines:

void update_time_txt(lv_timer_t* timer) { 
    lv_obj_t* time_label = (lv_obj_t*)lv_timer_get_user_data(timer);
    time_t result = time(NULL);
    struct tm *tm_info = localtime(&result);
    
    char buffer[32];
    strftime(buffer, sizeof(buffer), "%H:%M:%S %d/%m/%Y", tm_info);
    lv_label_set_text(time_label, buffer);
}

Stop me if I’m wrong, but I think I’m good at this moment. I tested it, the callback is triggered every second, the time is getting updated.

The problem

But there is a weird result in my LCD screen. The first text is fine:

But the second one is totally weird, and we can see at the right a 0, probably of the previous text. I don’t know why.

What I tried

To resolv this issue, I tried to put before the lv_label_set_text(time_label, buffer); this line:
lv_label_set_text(time_label, "");, even this line lv_label_set_text(time_label, NULL);.

I tried to remove all of this and I worked with int to see if it was a datetime problem, it is not. Even with int variable and the lv_label_set_text_fmt() function it is the same problem.

What I understand from the documentation is that lv_label_set_text(time_label, buffer); saves buffer in the memory, so buffer can be deleted, it will be printed anyway (not like lv_label_set_text_static().

The question

So how can I update my text every second to show the time ?

Thank you in advance.