-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Rust] Handling of panics by passing them to trace() #42
Comments
This looks amazing, thanks! Would it makes sense to include this in wasm4.rs somehow? |
It could be included. It needs to be called once to be used. Having it be in an init function that is called from |
I'm going to leave here for visibility how to set a panic hook handler in a // `src/lib.rs`
#![no_std]
// mod declarations
// other imports
use core::arch::wasm32;
use wasm4;
fn start() {}
fn update() {}
#[panic_handler]
fn panic_handler(panic_info: &core::panic::PanicInfo<'_>) -> ! {
wasm4::trace("panic error");
#[cfg(debug_assertions)]
if let Some(cause) = panic_info.payload().downcast_ref::<&str>() {
wasm4::trace(cause);
}
unsafe { wasm32::unreachable() }
}
Disabling in |
@FaberVitale That looks great! Should we add it to wasm4.rs? Does it work everywhere or only in |
You have to config a panic_handler if you are in
Yes if the template is going to be a I've left the comment here in case someone else wants to make a |
Adding this to
start()
will hook all panic messages (probably), unless it panics during a panic in which case it just crashes. If memory problems are present it will crash on alloc so we can't rely on.to_string()
.An
error(&str)
function could be added so that stack logs could be passed to the console as errors.The text was updated successfully, but these errors were encountered: