print stack trace for when an exception occurs

This commit is contained in:
2025-08-03 13:14:28 +01:00
parent a8ee1d5d37
commit 16fdfc7ac2
3 changed files with 24 additions and 1 deletions

View File

@@ -1,3 +1,6 @@
run_debug:
./build-unix-debug.sh && ./shf
run:
./build-unix.sh && ./shf

8
build-unix-debug.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
mlton -const 'Exn.keepHistory true' -link-opt "$(pkg-config --cflags glfw3) $(pkg-config --static --libs glfw3)" \
-export-header ffi/export.h \
shf.mlb \
ffi/glad.c \
ffi/glfw-export.c \
ffi/gles3-export.c \
ffi/glfw-input.c

View File

@@ -17,7 +17,19 @@ struct
fun loop (app: AppType.app_type, inputMailbox, drawMailbox) =
let
val inputMsg = Mailbox.recv inputMailbox
val app = AppUpdate.update (app, inputMsg)
val app =
AppUpdate.update (app, inputMsg)
handle e =>
let
(* print stack trace for debugging purposes,
* and then raise another exception to exit the program *)
val stackTrace = MLton.Exn.history e
val stackTrace = String.concatWith "\n" stackTrace
val () = print (stackTrace ^ "\n")
in
raise Empty
end
val () = sendMsgs (#msgs app, drawMailbox)
in
loop (app, inputMailbox, drawMailbox)