Improved reliability when creating/removing lots of value_str or objects

This commit is contained in:
fvanroie 2021-04-23 17:53:44 +02:00
parent b3e7f6d0e3
commit 761b3f02f3
2 changed files with 11 additions and 25 deletions

View File

@ -49,6 +49,7 @@ build_flags =
-D LV_LVGL_H_INCLUDE_SIMPLE ; for lv_drivers
-D LV_COMP_CONF_INCLUDE_SIMPLE ; for components
-D LV_SYMBOL_DEF_H ; don't load default symbol defines
-D LV_MEM_FULL_DEFRAG_CNT=4 ; stability: run lv_mem_defrag more frequently
; -- ESP build options ------------------------------------
-D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files
; -- ArduinoJson build options ----------------------------

View File

@ -232,7 +232,7 @@ void my_obj_set_value_str_txt(lv_obj_t* obj, uint8_t part, lv_state_t state, con
{
// LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__);
const void* value_str_p = lv_obj_get_style_value_str(obj, part);
void* value_str_p = (void*)lv_obj_get_style_value_str(obj, part);
lv_obj_invalidate(obj);
if(text == NULL || text[0] == 0) {
@ -262,36 +262,21 @@ void my_obj_set_value_str_txt(lv_obj_t* obj, uint8_t part, lv_state_t state, con
return;
}
// lv_obj_set_style_local_value_str(obj, part, state, str_p);
if(value_str_p == text) {
/*If set its own text then reallocate it (maybe its size changed)*/
LOG_DEBUG(TAG_ATTR, "%s %d", __FILE__, __LINE__);
return; // don't touch the data
// value_str_p = lv_mem_realloc(value_str_p, strlen(text) + 1);
// LV_ASSERT_MEM(value_str_p);
// if(value_str_p == NULL) return;
} else {
/*Free the old text*/
if(value_str_p != NULL) {
// LOG_DEBUG(TAG_ATTR, F("%s %d"), __FILE__, __LINE__);
lv_mem_free(value_str_p);
value_str_p = NULL;
// LOG_DEBUG(TAG_ATTR, F("%s %d"), __FILE__, __LINE__);
}
/*Get the size of the text*/
size_t len = strlen(text) + 1;
/*Allocate space for the new text*/
value_str_p = lv_mem_alloc(len);
LV_ASSERT_MEM(value_str_p);
if(value_str_p != NULL) strcpy((char*)value_str_p, text);
lv_obj_set_style_local_value_str(obj, part, state, (char*)value_str_p);
}
/*Get the size of the text*/
size_t len = strlen(text) + 1;
/*Allocate space for the new text*/
value_str_p = lv_mem_realloc(value_str_p, len);
LV_ASSERT_MEM(value_str_p);
if(value_str_p != NULL) strcpy((char*)value_str_p, text);
lv_obj_set_style_local_value_str(obj, part, state, (char*)value_str_p);
// LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__);
}