From 729d10592f4e802f91c555c309ff3ba4b119f843 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 19 Apr 2026 07:42:52 +0200 Subject: fix: WebGL frame rendering and opencut-wasm 0.2.8 --- rust/wasm/src/gpu.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'rust/wasm/src/gpu.rs') diff --git a/rust/wasm/src/gpu.rs b/rust/wasm/src/gpu.rs index 4e65978c..52c051f0 100644 --- a/rust/wasm/src/gpu.rs +++ b/rust/wasm/src/gpu.rs @@ -19,9 +19,27 @@ thread_local! { static GPU_RUNTIME: RefCell> = const { RefCell::new(None) }; } +fn set_panic_hook() { + static SET_HOOK: std::sync::Once = std::sync::Once::new(); + SET_HOOK.call_once(|| { + std::panic::set_hook(Box::new(|info| { + // Store the full panic message in window.__wasmPanic so the JS catch block + // can surface it instead of the opaque "Unreachable" WASM trap message. + if let Some(window) = web_sys::window() { + let _ = Reflect::set( + &window, + &JsValue::from_str("__wasmPanic"), + &JsValue::from_str(&info.to_string()), + ); + } + console_error_panic_hook::hook(info); + })); + }); +} + #[wasm_bindgen(js_name = initializeGpu)] pub async fn initialize_gpu() -> Result<(), JsValue> { - console_error_panic_hook::set_once(); + set_panic_hook(); if GPU_RUNTIME.with(|runtime| runtime.borrow().is_some()) { return Ok(()); -- cgit v1.3.1