Skip to content

Commit

Permalink
fixup! fix: remove lvgl event callback on component deletion This cau…
Browse files Browse the repository at this point in the history
…se a segfault

Previous fix was applied to a location where the underlying lv object could already have been deleted.
And therefore, could cause a segfault.
  • Loading branch information
EmixamPP committed Aug 26, 2024
1 parent af11712 commit dd17997
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/render/native/components/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ void NativeComponentMaskInit (JSContext* ctx, JSValue ns);
#define WRAPPED_JS_CLOSE_COMPONENT(COMPONENT,COMPONENT_NAME) \
static JSValue NativeCompCloseComponent(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { \
COMP_REF* s = (COMP_REF*)JS_GetOpaque(this_val, COMPONENT##ClassID); \
lv_obj_del_async(((BasicComponent*)(s->comp))->instance); \
lv_obj_t* instance = ((BasicComponent*)(s->comp))->instance; \
((BasicComponent*)(s->comp))->instance = nullptr; \
lv_obj_remove_event_cb(instance, &BasicComponent::EventCallback); \
lv_obj_del_async(instance); \
return JS_UNDEFINED; \
} \
\
Expand Down
4 changes: 1 addition & 3 deletions src/render/native/core/basic/comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,11 @@ void BasicComponent::setBackgroundImage (uint8_t* buf, size_t buf_len, int32_t s
};

BasicComponent::~BasicComponent () {
removeEventListener(0);

comp_map.erase(this->uid);

const lv_coord_t* ptr1 = this->grid_row_desc;
const lv_coord_t* ptr2 = this->grid_column_desc;

for(auto& desc : this->image_desc_map) {
if (desc.second != nullptr) {
const uint8_t* buf = (static_cast<lv_img_dsc_t_1*>(desc.second))->data;
Expand Down

0 comments on commit dd17997

Please sign in to comment.