From 15251a18a2480fb4c623b2c6f2005be54aa91143 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Mon, 4 Aug 2025 22:54:32 +0200 Subject: [PATCH 1/2] Fix animations not working by removing deadlock --- .gitignore | 1 + frontend/wasm/src/editor_api.rs | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index bdfa416126..3fa518041e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ target/ *.exrc perf.data* profile.json +profile.json.gz flamegraph.svg .idea/ .direnv diff --git a/frontend/wasm/src/editor_api.rs b/frontend/wasm/src/editor_api.rs index db8dd7dfb8..a639b1cc8c 100644 --- a/frontend/wasm/src/editor_api.rs +++ b/frontend/wasm/src/editor_api.rs @@ -239,7 +239,8 @@ impl EditorHandle { wasm_bindgen_futures::spawn_local(poll_node_graph_evaluation()); if !EDITOR_HAS_CRASHED.load(Ordering::SeqCst) { - editor_and_handle(|_, handle| { + handle(|handle| { + log::debug!("animation frame"); handle.dispatch(InputPreprocessorMessage::CurrentTime { timestamp: js_sys::Date::now() as u64, }); @@ -914,7 +915,10 @@ fn set_timeout(f: &Closure, delay: Duration) { fn editor(callback: impl FnOnce(&mut editor::application::Editor) -> T) -> T { EDITOR.with(|editor| { let mut guard = editor.try_lock(); - let Ok(Some(editor)) = guard.as_deref_mut() else { return T::default() }; + let Ok(Some(editor)) = guard.as_deref_mut() else { + log::error!("Failed to borrow editor"); + return T::default(); + }; callback(editor) }) @@ -922,19 +926,26 @@ fn editor(callback: impl FnOnce(&mut editor::application::Editor) -> /// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments. pub(crate) fn editor_and_handle(callback: impl FnOnce(&mut Editor, &mut EditorHandle)) { - EDITOR_HANDLE.with(|editor_handle| { + handle(|editor_handle| { editor(|editor| { - let mut guard = editor_handle.try_lock(); - let Ok(Some(editor_handle)) = guard.as_deref_mut() else { - log::error!("Failed to borrow editor handle"); - return; - }; - // Call the closure with the editor and its handle callback(editor, editor_handle); }) }); } +/// Provides access to the `EditorHandle` by calling the given closure with them as arguments. +pub(crate) fn handle(callback: impl FnOnce(&mut EditorHandle)) { + EDITOR_HANDLE.with(|editor_handle| { + let mut guard = editor_handle.try_lock(); + let Ok(Some(editor_handle)) = guard.as_deref_mut() else { + log::error!("Failed to borrow editor handle"); + return; + }; + + // Call the closure with the editor and its handle + callback(editor_handle); + }); +} async fn poll_node_graph_evaluation() { // Process no further messages after a crash to avoid spamming the console From ebc3490bf0044030c82c5bec7b79299aa0531a23 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Tue, 5 Aug 2025 00:30:14 +0200 Subject: [PATCH 2/2] Remove log --- frontend/wasm/src/editor_api.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/wasm/src/editor_api.rs b/frontend/wasm/src/editor_api.rs index a639b1cc8c..617231b74e 100644 --- a/frontend/wasm/src/editor_api.rs +++ b/frontend/wasm/src/editor_api.rs @@ -240,7 +240,6 @@ impl EditorHandle { if !EDITOR_HAS_CRASHED.load(Ordering::SeqCst) { handle(|handle| { - log::debug!("animation frame"); handle.dispatch(InputPreprocessorMessage::CurrentTime { timestamp: js_sys::Date::now() as u64, });