Skip to content

Commit

Permalink
Workaround winit bug where events execute immediately (rust-windowing#4)
Browse files Browse the repository at this point in the history
Winit on web has a bug where the EventLoopProxy will immediately call handlers for a custom event in send_event instead of scheduling it for the next event tick. This causes double-borrows of our MutableAppContext, which hard crashes the app. This is a bandaid fix which pushes those calls on the microtask queue instead.
  • Loading branch information
ddfisher authored May 17, 2024
1 parent 4cdd894 commit 1813f60
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/platform_impl/web/event_loop/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ impl<T: 'static> EventLoopProxy<T> {

pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
self.sender.send(event).map_err(|SendError(event)| EventLoopClosed(event))?;
self.runner.wake();

// Workaround: the we should never be immediately executing new things on the event loop!
let runner = self.runner.clone();
wasm_bindgen_futures::spawn_local(async move {
runner.wake();
});

Ok(())
}
}
Expand Down

0 comments on commit 1813f60

Please sign in to comment.