From 746b1794787aebc53affac48b90d91f59c5a91bc Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 29 Jul 2023 18:19:10 +0200 Subject: [PATCH] ui: force alignment of modal callback function 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 https://git.qcode.ch/nakamochi/ndg/pulls/20 ref https://git.qcode.ch/nakamochi/ndg/issues/5 --- src/ui/poweroff.zig | 2 +- src/ui/widget.zig | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/poweroff.zig b/src/ui/poweroff.zig index 2ff9c14..aa408f4 100644 --- a/src/ui/poweroff.zig +++ b/src/ui/poweroff.zig @@ -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; diff --git a/src/ui/widget.zig b/src/ui/widget.zig index 4729347..a179215 100644 --- a/src/ui/widget.zig +++ b/src/ui/widget.zig @@ -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);