Skip to content

Commit

Permalink
Fix a possible double-borrow during event handling (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanisaacg authored Apr 11, 2020
1 parent 0bc58f6 commit a8e777a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- On X11, fix `ResumeTimeReached` being fired too early.
- On Web, fix a possible panic during event handling

# 0.22.0 (2020-03-09)

Expand Down
5 changes: 3 additions & 2 deletions src/platform_impl/web/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ impl<T: 'static> Shared<T> {
// It should only ever be called from send_event
fn handle_event(&self, event: Event<'static, T>, control: &mut root::ControlFlow) {
let is_closed = self.is_closed();

match *self.0.runner.borrow_mut() {
Some(ref mut runner) => {
// An event is being processed, so the runner should be marked busy
Expand All @@ -227,7 +226,9 @@ impl<T: 'static> Shared<T> {
// If the runner doesn't exist and this method recurses, it will recurse infinitely
if !is_closed && self.0.runner.borrow().is_some() {
// Take an event out of the queue and handle it
if let Some(event) = self.0.events.borrow_mut().pop_front() {
// Make sure not to let the borrow_mut live during the next handle_event
let event = { self.0.events.borrow_mut().pop_front() };
if let Some(event) = event {
self.handle_event(event, control);
}
}
Expand Down

0 comments on commit a8e777a

Please sign in to comment.