(panic_info: String)
| 82 | |
| 83 | return; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | EDITOR_HAS_CRASHED.store(true, Ordering::SeqCst); |
| 88 | |
| 89 | log::error!("{info}"); |
| 90 | |
| 91 | // Prefer using the raw JS callback to avoid mutex lock contention inside the panic hook. |
| 92 | if let Err(info) = send_panic_dialog_via_callback(info) { |
| 93 | send_panic_dialog_deferred(info); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | fn send_panic_dialog_via_callback(panic_info: String) -> Result<(), String> { |
| 98 | let message = PanicDialogMessage::DisplayDialogPanic { panic_info: panic_info.clone() }; |
| 99 | let Ok(message_data) = serde_wasm_bindgen::to_value(&message) else { |
| 100 | log::error!("Failed to serialize crash dialog panic message"); |
| 101 | return Err(panic_info); |
| 102 | }; |
| 103 | |
| 104 | PANIC_DIALOG_MESSAGE_CALLBACK.with(|callback| { |
| 105 | let callback_ref = callback.borrow(); |
| 106 | let Some(callback) = callback_ref.as_ref() else { |
| 107 | return Err(panic_info); |
| 108 | }; |
| 109 | |
| 110 | if let Err(error) = callback.call2(&JsValue::null(), &JsValue::from("DisplayDialogPanic"), &message_data) { |
| 111 | log::error!("Failed to send crash dialog panic message to JS: {error:?}"); |
| 112 | return Err(panic_info); |
| 113 | } |
| 114 | |
| 115 | Ok(()) |
| 116 | }) |
| 117 | } |
no test coverage detected