Skip to content

Commit 15251a1

Browse files
TrueDoctorKeavon
authored andcommitted
Fix animations not working by removing deadlock
1 parent 4b11dce commit 15251a1

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ target/
33
*.exrc
44
perf.data*
55
profile.json
6+
profile.json.gz
67
flamegraph.svg
78
.idea/
89
.direnv

frontend/wasm/src/editor_api.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ impl EditorHandle {
239239
wasm_bindgen_futures::spawn_local(poll_node_graph_evaluation());
240240

241241
if !EDITOR_HAS_CRASHED.load(Ordering::SeqCst) {
242-
editor_and_handle(|_, handle| {
242+
handle(|handle| {
243+
log::debug!("animation frame");
243244
handle.dispatch(InputPreprocessorMessage::CurrentTime {
244245
timestamp: js_sys::Date::now() as u64,
245246
});
@@ -914,27 +915,37 @@ fn set_timeout(f: &Closure<dyn FnMut()>, delay: Duration) {
914915
fn editor<T: Default>(callback: impl FnOnce(&mut editor::application::Editor) -> T) -> T {
915916
EDITOR.with(|editor| {
916917
let mut guard = editor.try_lock();
917-
let Ok(Some(editor)) = guard.as_deref_mut() else { return T::default() };
918+
let Ok(Some(editor)) = guard.as_deref_mut() else {
919+
log::error!("Failed to borrow editor");
920+
return T::default();
921+
};
918922

919923
callback(editor)
920924
})
921925
}
922926

923927
/// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments.
924928
pub(crate) fn editor_and_handle(callback: impl FnOnce(&mut Editor, &mut EditorHandle)) {
925-
EDITOR_HANDLE.with(|editor_handle| {
929+
handle(|editor_handle| {
926930
editor(|editor| {
927-
let mut guard = editor_handle.try_lock();
928-
let Ok(Some(editor_handle)) = guard.as_deref_mut() else {
929-
log::error!("Failed to borrow editor handle");
930-
return;
931-
};
932-
933931
// Call the closure with the editor and its handle
934932
callback(editor, editor_handle);
935933
})
936934
});
937935
}
936+
/// Provides access to the `EditorHandle` by calling the given closure with them as arguments.
937+
pub(crate) fn handle(callback: impl FnOnce(&mut EditorHandle)) {
938+
EDITOR_HANDLE.with(|editor_handle| {
939+
let mut guard = editor_handle.try_lock();
940+
let Ok(Some(editor_handle)) = guard.as_deref_mut() else {
941+
log::error!("Failed to borrow editor handle");
942+
return;
943+
};
944+
945+
// Call the closure with the editor and its handle
946+
callback(editor_handle);
947+
});
948+
}
938949

939950
async fn poll_node_graph_evaluation() {
940951
// Process no further messages after a crash to avoid spamming the console

0 commit comments

Comments
 (0)