I guess there is no harm in adding lv_obj_del_safe for a case like that.
As a personal preference, though, I would prefer to fix the code in the event that someone left dangling pointers, rather than relying on the library to spot it for me. But that’s just my opinion.
I agree. If you relied on the library will spot the dirty pointer then we would need lv_label_create_safe() (what if the parent is invalid) lv_label_set_text_safe (what if the label is invalid) and so on.
IMO, helping the user to find the issue is more reasonable.
@kisvegabor I disagree with this assertion:
" I agree. If you relied on the library will spot the dirty pointer then we would need lv_label_create_safe() (what if the parent is invalid) lv_label_set_text_safe (what if the label is invalid) and so on."
2 points:
First of all - I am not suggesting reliance on the library, not at all (To ref @embeddedt’s comment, I agree totally. That is why I would never use this code path in development. Thats where you WANT to see bugs). What I am suggesting, is in complicated, long running systems, bugs surface that you had no clue you were there. Back to the code path comment.
Second - The application would be slowed in the event of this code path, and I would not suggest it for every case, but in the case of a complicated thing, that changed a lot, I would indeed want to use it for safety.
agreed, I too would want to fix the code as well. And this would be a good place for telemetry, to tell me that the safe delete spotted something that was amiss.
However, issues can occur in other functions too. Why do we pick only lv_obj_del?
Having issues with lv_obj_get_parent() or lv_obj_get_width is similarly likely.
If the goal is to leave certain protection in production code too it’d be possible to make the checks configurable. E.g.:
Which makes me think it would be better to add lv_obj_valid (and possibly lv_obj_check_type), both of which would return bool and could be used in a project-specific assertion.
@kisvegabor Debug mode on every function call may still be viable. Either way it will lead to a documentation “bug”
We will need to call out the functionality, maybe in a debugging section. I believe adding these options will make lvgl a lot easier to use for less experienced people
Seeing if we are in Debug or not is platform dependent. IMO is should be enabled by default in the simulator (also add log entry to tell “we are in debug mode which is safe but slow”) but disabled in lv_conf_templ.h.
One day we should have a chat about some ideas I have and possible plans for 7.0…
I think lvgl is amazing (Hence why I am giving my time to it, sigh not enough of that), and I think with a few additions it could really be the best out there.