Skip to content

Commit bee0e8d

Browse files
committed
Fix assert handler
1 parent a22cd6a commit bee0e8d

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function build_zig {
9393
-DLV_USE_LOG=1 \
9494
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
9595
-DLV_LOG_TRACE_OBJ_CREATE=1 \
96+
-DLV_LOG_TRACE_TIMER=1 \
9697
-DLV_MEM_SIZE=1000000 \
9798
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
9899
-I . \
@@ -227,6 +228,7 @@ function compile_lvgl {
227228
-DLV_USE_LOG=1 \
228229
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
229230
-DLV_LOG_TRACE_OBJ_CREATE=1 \
231+
-DLV_LOG_TRACE_TIMER=1 \
230232
-DLV_MEM_SIZE=1000000 \
231233
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
232234
\

lvglwasm.wasm

-12.2 KB
Binary file not shown.

lvglwasm.zig

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub export fn lv_demo_widgets() void {
4444
c.lv_log_register_print_cb(custom_logger);
4545

4646
// Init LVGL
47+
debug("before lv_init", .{}); ////
4748
c.lv_init();
49+
debug("after lv_init", .{}); ////
4850

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

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

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

190-
///////////////////////////////////////////////////////////////////////////////
191-
// Panic Handler
192-
193-
/// Called by Zig when it hits a Panic. We print the Panic Message, Stack Trace and halt. See
194-
/// https://andrewkelley.me/post/zig-stack-traces-kernel-panic-bare-bones-os.html
195-
/// https://github.com/ziglang/zig/blob/master/lib/std/builtin.zig#L763-L847
196-
pub fn panic(message: []const u8, _stack_trace: ?*std.builtin.StackTrace) noreturn {
197-
// Print the Panic Message
198-
_ = _stack_trace;
199-
wasmlog.Console.log("\n!ZIG PANIC!\n{s}", .{message});
200-
201-
// TODO: Print the Stack Trace
202-
wasmlog.Console.log("Stack Trace:", .{});
203-
var it = std.debug.StackIterator.init(@returnAddress(), null);
204-
while (it.next()) |return_address| {
205-
wasmlog.Console.log("{}", .{@intCast(i32, return_address)});
206-
}
207-
208-
// Halt
209-
while (true) {
210-
wasmlog.Console.log("Halted", .{});
211-
}
212-
}
213-
214192
///////////////////////////////////////////////////////////////////////////////
215193
// Logging
216194

0 commit comments

Comments
 (0)