Patch memory leak

This commit is contained in:
fvanroie 2021-04-23 00:41:53 +02:00
parent 0aece4f29f
commit b3e7f6d0e3
3 changed files with 30 additions and 9 deletions

View File

@ -555,3 +555,14 @@ void cpicker_event_handler(lv_obj_t* obj, lv_event_t event)
// dispatch_normalized_group_value(obj->user_data.groupid, obj, val, min, max); // dispatch_normalized_group_value(obj->user_data.groupid, obj, val, min, max);
} }
/**
* Called when an object is deleted
* @param obj pointer to a generic object
* @param event type of event that occured
*/
void deleted_event_handler(lv_obj_t* obj, lv_event_t event)
{
uint8_t hasp_event_id;
translate_event(obj, event, hasp_event_id);
}

View File

@ -18,6 +18,7 @@ void slider_event_handler(lv_obj_t* obj, lv_event_t event);
void selector_event_handler(lv_obj_t* obj, lv_event_t event); void selector_event_handler(lv_obj_t* obj, lv_event_t event);
void btnmatrix_event_handler(lv_obj_t* obj, lv_event_t event); void btnmatrix_event_handler(lv_obj_t* obj, lv_event_t event);
void cpicker_event_handler(lv_obj_t* obj, lv_event_t event); void cpicker_event_handler(lv_obj_t* obj, lv_event_t event);
void deleted_event_handler(lv_obj_t* obj, lv_event_t event);
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
void event_gpio_input(uint8_t pin, uint8_t group, uint8_t eventid); void event_gpio_input(uint8_t pin, uint8_t group, uint8_t eventid);

View File

@ -489,16 +489,20 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id)
case LV_HASP_PAGE: case LV_HASP_PAGE:
case HASP_OBJ_PAGE: case HASP_OBJ_PAGE:
obj = lv_page_create(parent_obj, NULL); obj = lv_page_create(parent_obj, NULL);
if(obj) obj->user_data.objid = LV_HASP_PAGE; if(obj) {
// No event handler for pages obj->user_data.objid = LV_HASP_PAGE;
lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation
}
break; break;
#if LV_USE_WIN && LVGL_VERSION_MAJOR == 7 #if LV_USE_WIN && LVGL_VERSION_MAJOR == 7
case LV_HASP_WINDOW: case LV_HASP_WINDOW:
case HASP_OBJ_WIN: case HASP_OBJ_WIN:
obj = lv_win_create(parent_obj, NULL); obj = lv_win_create(parent_obj, NULL);
if(obj) obj->user_data.objid = LV_HASP_WINDOW; if(obj) {
// No event handler for pages obj->user_data.objid = LV_HASP_WINDOW;
lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation
}
break; break;
#endif #endif
@ -550,16 +554,18 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id)
case LV_HASP_TILEVIEW: case LV_HASP_TILEVIEW:
case HASP_OBJ_TILEVIEW: case HASP_OBJ_TILEVIEW:
obj = lv_tileview_create(parent_obj, NULL); obj = lv_tileview_create(parent_obj, NULL);
if(obj) obj->user_data.objid = LV_HASP_TILEVIEW; if(obj) {
obj->user_data.objid = LV_HASP_TILEVIEW;
// No event handler for tileviews lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation
}
break; break;
case LV_HASP_TABVIEW: case LV_HASP_TABVIEW:
case HASP_OBJ_TABVIEW: case HASP_OBJ_TABVIEW:
obj = lv_tabview_create(parent_obj, NULL); obj = lv_tabview_create(parent_obj, NULL);
// No event handler for tabs
if(obj) { if(obj) {
lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation
lv_obj_t* tab; lv_obj_t* tab;
tab = lv_tabview_add_tab(obj, "tab 1"); tab = lv_tabview_add_tab(obj, "tab 1");
// lv_obj_set_user_data(tab, id + 1); // lv_obj_set_user_data(tab, id + 1);
@ -587,7 +593,10 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id)
case LV_HASP_SPINNER: case LV_HASP_SPINNER:
case HASP_OBJ_SPINNER: case HASP_OBJ_SPINNER:
obj = lv_spinner_create(parent_obj, NULL); obj = lv_spinner_create(parent_obj, NULL);
if(obj) obj->user_data.objid = LV_HASP_SPINNER; if(obj) {
obj->user_data.objid = LV_HASP_SPINNER;
lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation
}
break; break;
#endif #endif