-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Segfault of as_zmk_battery_state_changed
on native_posix_64
#2792
Comments
See zmkfirmware#2792 where this cause segfault.
It feels weird to me that the The battery status widget is the only widget that actually uses the event parameter. If it is a battery event, it reads from the event. If it is some other type of event, it still has to populate the entire state struct though, and it can't get it from the event, so it has to read it from elsewhere. The rest of the widgets just ignore the event entirely. Why even pass the event if we're mostly not going to use it? Some alternative designs to consider:
// Option 1
static struct foo_state foo_get_state(void) {
// Regardless of which of a or b changed (or neither on startup), we must populate every field
return (struct foo_state) {
.a = get_current_a(),
.b = get_current_b(),
};
}
ZMK_DISPLAY_WIDGET_LISTENER(widget_foo, struct foo_state, foo_update_cb, foo_get_state);
ZMK_SUBSCRIPTION(widget_foo, a_changed);
ZMK_SUBSCRIPTION(widget_foo, b_changed);
// Option 2
static struct foo_state foo_init_state(void) {
// This is called once on startup and has to populate every field
return (struct foo_state) {
.a = get_current_a(),
.b = get_current_b(),
};
}
static void foo_update_state(struct foo_state* state, const zmk_event_t* eh) {
const struct a_changed* a;
const struct b_changed* b;
// Only update the fields that changed using the event data instead of calling other functions.
if ((a = as_a_changed(eh)) != NULL) {
state->a = a->value;
} else if ((b = as_b_changed(eh)) != NULL) {
state->b = b->value;
}
}
ZMK_DISPLAY_WIDGET_LISTENER(widget_foo, struct foo_state, foo_update_cb, foo_init_state, foo_update_state);
ZMK_SUBSCRIPTION(widget_foo, a_changed);
ZMK_SUBSCRIPTION(widget_foo, b_changed); @petejohanson what are your thoughts on this? |
At the following config, when building on
native_posix_64
, it will segfault during init process:GDB backtrace:
Cause by the
event_manager
macro#define ZMK_EVENT_IMPL(event_type)
, instruct event_type *as_##event_type(const zmk_event_t *eh)
which doesn't check theeh
pointer is NULL or not:The text was updated successfully, but these errors were encountered: