diff --git a/capi/Cargo.toml b/capi/Cargo.toml index 6f55727a..a895927f 100644 --- a/capi/Cargo.toml +++ b/capi/Cargo.toml @@ -8,10 +8,11 @@ edition = "2018" livesplit-core = { path = "..", default-features = false, features = ["std"] } serde_json = "1.0.8" time = { version = "0.3.4" } +console_error_panic_hook = { version = "0.1.7", optional = true } [features] default = ["image-shrinking"] image-shrinking = ["livesplit-core/image-shrinking"] software-rendering = ["livesplit-core/software-rendering"] -wasm-web = ["livesplit-core/wasm-web"] +wasm-web = ["livesplit-core/wasm-web", "console_error_panic_hook"] auto-splitting = ["livesplit-core/auto-splitting"] diff --git a/capi/src/lib.rs b/capi/src/lib.rs index e3437728..1cf330f4 100644 --- a/capi/src/lib.rs +++ b/capi/src/lib.rs @@ -11,6 +11,8 @@ use std::{ ptr, }; +extern crate console_error_panic_hook; + pub mod analysis; pub mod auto_splitting_runtime; pub mod atomic_date_time; @@ -193,3 +195,12 @@ pub extern "C" fn dealloc(ptr: *mut u8, cap: usize) { pub extern "C" fn get_buf_len() -> usize { OUTPUT_VEC.with(|v| v.borrow().len() - 1) } + + +/// sets the console error panic hook +/// this means that when rust panics in wasm, the panic message will be sent to js console +#[cfg(feature = "wasm-web")] +#[no_mangle] +pub extern "C" fn initialize_debugging() { + console_error_panic_hook::set_once(); +} \ No newline at end of file