lvgl / lv_port_pc_eclipse

PC simulator project for LVGL embedded GUI Library. Recommended on Linux and Mac.
https://docs.lvgl.io/v7/en/html/get-started/pc-simulator.html
MIT License
278 stars 214 forks source link

c++ std::shared_ptr don't work with lvgl #155

Open Cun-Jiang opened 1 week ago

Cun-Jiang commented 1 week ago

I want to use std::shared_ptr but it doesn't seem to be working. Is lvgl not supporting std::shared_ptr?

auto *container=lv_obj_create(lv_screen_active());
lv_obj_set_size(container,200,200);
v_obj_center(container);
lv_obj_set_style_bg_color(container,lv_color_hex(0xffdfba),LV_PART_MAIN);

Screenshot_2024-10-06_23-23-43

auto container = std::shared_ptr<lv_obj_t>(lv_obj_create(lv_screen_active()), [](lv_obj_t* obj) {
lv_obj_del(obj); // Custom deleter to handle object deletion
});
lv_obj_set_size(container.get(), 200, 200);
lv_obj_set_style_bg_color(container.get(),lv_color_hex(0xffdfba),LV_PART_MAIN);

Screenshot_2024-10-06_23-27-33

kisvegabor commented 5 days ago

I mostly in C and don't really use C++ or shared pointers, so unfortunately I can't comment much. What I can say is that by design we haven't considered shared pointers specifically. However I can't see why it shouldn't work, once you can pass a custom delete functions.

Can you try with debugger if lv_obj_delete is called?