Lv_label_set_text_fmt -> Strings with different lengths?



I am having trouble with rewriting lv_label with lv_label_set_text_fmt function. When I send there a first String, it always works fine. But anytime I continue with sending there another one, usually longer one, it shows just “X?” or “H?”. I assume it has something to do with the buffer and memory, or so?

NOTE: Please keep in mind that this simplified example could of course work a lot easier and I wouldn’t have to use lv_label_set_text_fmt. However, in my case I have to use this function, it is mainly a principle.

EDIT: I found out that Strings longer than 10 characters make problems…

Thank you for all your effort and time!

Board: NodeMCU ESP32S

LVGL version: v8.1


/* simplified */
#include <lvgl.h>
#include <Arduino.h>

lv_obj_t *label_product;

label_product = lv_label_create(lv_scr_act());
lv_label_set_text(label_product, "text");
lv_obj_align(label_product, LV_ALIGN_TOP_MID, 0, 60);

String product_name = "short";
lv_label_set_text_fmt(label_product, "%s", product_name);

// Something is happening

product_name = "loooooooong";
lv_label_set_text_fmt(label_product, "%s", product_name);

I don’t use Arduino, so this is just an educated guess, but you could try:

lv_label_set_text_fmt(label_product, "%s", product_name.c_str());

I’m not sure whether the Arduino String type is directly compatible with printf-style functions or if it needs to be converted to char * first using c_str().