From 823b4d98ffb8aced792e9e3844cc1bfaf3e493f5 Mon Sep 17 00:00:00 2001 From: Hurricane996 Date: Tue, 18 Jan 2022 20:35:00 -0600 Subject: [PATCH 1/2] Added console_error_panic_hook to make debugging livesplit-core in a wasm context (currently only LiveSplitOne web) easier --- capi/Cargo.toml | 1 + capi/src/lib.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/capi/Cargo.toml b/capi/Cargo.toml index 6f55727a..4f20e624 100644 --- a/capi/Cargo.toml +++ b/capi/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" livesplit-core = { path = "..", default-features = false, features = ["std"] } serde_json = "1.0.8" time = { version = "0.3.4" } +console_error_panic_hook = "0.1.7" [features] default = ["image-shrinking"] diff --git a/capi/src/lib.rs b/capi/src/lib.rs index e3437728..cd22a993 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,8 @@ 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) } + +#[no_mangle] +pub extern "C" fn initialize_debugging() { + console_error_panic_hook::set_once(); +} \ No newline at end of file From 59a8bee6f683c8151b3e67be62af1353263101f8 Mon Sep 17 00:00:00 2001 From: Hurricane996 Date: Tue, 18 Jan 2022 20:40:18 -0600 Subject: [PATCH 2/2] conditionally compile wasm debug changes only when compiling for wasm-web --- capi/Cargo.toml | 4 ++-- capi/src/lib.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/capi/Cargo.toml b/capi/Cargo.toml index 4f20e624..a895927f 100644 --- a/capi/Cargo.toml +++ b/capi/Cargo.toml @@ -8,11 +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 = "0.1.7" +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 cd22a993..1cf330f4 100644 --- a/capi/src/lib.rs +++ b/capi/src/lib.rs @@ -196,6 +196,10 @@ 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();