From 761b3f02f31415095e08699e63b3d4dc256b2cb5 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 23 Apr 2021 17:53:44 +0200 Subject: [PATCH] Improved reliability when creating/removing lots of value_str or objects --- platformio.ini | 1 + src/hasp/hasp_attribute.cpp | 35 ++++++++++------------------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7a9383b3..3aab2a92 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 ---------------------------- diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 547a0a8e..f72b7831 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -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__); }