From 54ce6a21a0722e408ae49c74f5008005fc1e4cbf Mon Sep 17 00:00:00 2001 From: Osspial Date: Sun, 18 Nov 2018 19:12:45 -0500 Subject: [PATCH] Fix buffered events not getting dispatched --- src/platform_impl/windows/event_loop.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 6c7090d7c..c7f989d51 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -297,9 +297,26 @@ impl ELRShared { if let Ok(mut runner_ref) = self.runner.try_borrow_mut() { if let Some(ref mut runner) = *runner_ref { runner.process_event(event); + + // Dispatch any events that were buffered during the call to `process_event`. + loop { + // We do this instead of using a `while let` loop because if we use a `while let` + // loop the reference returned `borrow_mut()` doesn't get dropped until the end + // of the loop's body and attempts to add events to the event buffer while in + // `process_event` will fail. + let buffered_event_opt = self.buffer.borrow_mut().pop_front(); + match buffered_event_opt { + Some(event) => runner.process_event(event), + None => break + } + } + return; } } + + // If the runner is already borrowed, we're in the middle of an event loop invocation. Add + // the event to a buffer to be processed later. self.buffer.borrow_mut().push_back(event) } }