ui: force alignment of modal callback function
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details

fullscreen modal dialog was added in 4297c139. the callback function to
that modal *must* be aligned according to the target architecture.
failing to do so may result in "incorrect alignment" panic.

this somehow worked in 4297c139 but sometimes panic. i suspect this may
be due to PIE-enabled build, possibly in conjuction with some zig v0.10
compiler bugs.

ref #20
ref #5
pull/24/head v0.2.0
alex 1 year ago
parent 63eb27bf18
commit 746b179478
Signed by: x1ddos
GPG Key ID: FDEFB4A63CBD8460

@ -31,7 +31,7 @@ export fn nm_poweroff_btn_callback(_: *lvgl.LvEvent) void {
}
/// poweroff confirmation screen callback.
fn poweroffModalCallback(btn_idx: usize) void {
fn poweroffModalCallback(btn_idx: usize) align(@alignOf(widget.ModalButtonCallbackFn)) void {
// proceed = 0, cancel = 1
if (btn_idx != 0) {
return;

@ -50,10 +50,12 @@ pub const ModalButtonCallbackFn = *const fn (index: usize) void;
/// while all heap-alloc'ed resources are free'd automatically right before cb is called,
/// the value of title, text and btns args must live at least as long as cb; they are
/// memory-managed by the callers.
///
/// note: the cb callback must have @alignOf(ModalbuttonCallbackFn) alignment.
pub fn modal(title: [*:0]const u8, text: [*:0]const u8, btns: []const [*:0]const u8, cb: ModalButtonCallbackFn) !void {
const win = try lvgl.createWindow(null, 60, title);
errdefer win.winobj.destroy(); // also deletes all children created below
win.winobj.setUserdata(@ptrCast(?*const anyopaque, cb));
win.winobj.setUserdata(cb);
const wincont = win.content();
wincont.flexFlow(.column);