Skip to content

Commit

Permalink
Fix assert handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed May 27, 2023
1 parent a22cd6a commit bee0e8d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function build_zig {
-DLV_USE_LOG=1 \
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
-DLV_LOG_TRACE_OBJ_CREATE=1 \
-DLV_LOG_TRACE_TIMER=1 \
-DLV_MEM_SIZE=1000000 \
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
-I . \
Expand Down Expand Up @@ -227,6 +228,7 @@ function compile_lvgl {
-DLV_USE_LOG=1 \
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
-DLV_LOG_TRACE_OBJ_CREATE=1 \
-DLV_LOG_TRACE_TIMER=1 \
-DLV_MEM_SIZE=1000000 \
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
\
Expand Down
Binary file modified lvglwasm.wasm
Binary file not shown.
30 changes: 4 additions & 26 deletions lvglwasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub export fn lv_demo_widgets() void {
c.lv_log_register_print_cb(custom_logger);

// Init LVGL
debug("before lv_init", .{}); ////
c.lv_init();
debug("after lv_init", .{}); ////

// Fetch pointers to Display Driver and Display Buffer
const disp_drv = c.get_disp_drv();
Expand Down Expand Up @@ -177,40 +179,16 @@ export fn millis() u32 {
/// Number of elapsed milliseconds
var elapsed_ms: u32 = 0;

/// TODO: Print a Stack Trace on Assertion Failure and halt
/// On Assertion Failure, print a Stack Trace and halt
export fn lv_assert_handler() void {
wasmlog.Console.log("*** lv_assert_handler: ASSERTION FAILED", .{});
@panic("*** lv_assert_handler: ASSERTION FAILED");
}

/// Custom Logger for LVGL that writes to JavaScript Console
export fn custom_logger(buf: [*c]const u8) void {
wasmlog.Console.log("{s}", .{buf});
}

///////////////////////////////////////////////////////////////////////////////
// Panic Handler

/// Called by Zig when it hits a Panic. We print the Panic Message, Stack Trace and halt. See
/// https://andrewkelley.me/post/zig-stack-traces-kernel-panic-bare-bones-os.html
/// https://github.com/ziglang/zig/blob/master/lib/std/builtin.zig#L763-L847
pub fn panic(message: []const u8, _stack_trace: ?*std.builtin.StackTrace) noreturn {
// Print the Panic Message
_ = _stack_trace;
wasmlog.Console.log("\n!ZIG PANIC!\n{s}", .{message});

// TODO: Print the Stack Trace
wasmlog.Console.log("Stack Trace:", .{});
var it = std.debug.StackIterator.init(@returnAddress(), null);
while (it.next()) |return_address| {
wasmlog.Console.log("{}", .{@intCast(i32, return_address)});
}

// Halt
while (true) {
wasmlog.Console.log("Halted", .{});
}
}

///////////////////////////////////////////////////////////////////////////////
// Logging

Expand Down

0 comments on commit bee0e8d

Please sign in to comment.