Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Cun-Jiang opened this issue Oct 6, 2024 · 1 comment
Open

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

Cun-Jiang opened this issue Oct 6, 2024 · 1 comment

Comments

@Cun-Jiang
Copy link

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants