Fix a possible double-borrow during event handling (#1512)

This commit is contained in:
Ryan G 2020-04-11 15:20:38 -04:00 committed by GitHub
parent 0bc58f695b
commit a8e777a5df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -1,6 +1,7 @@
# Unreleased # Unreleased
- On X11, fix `ResumeTimeReached` being fired too early. - On X11, fix `ResumeTimeReached` being fired too early.
- On Web, fix a possible panic during event handling
# 0.22.0 (2020-03-09) # 0.22.0 (2020-03-09)

View file

@ -202,7 +202,6 @@ impl<T: 'static> Shared<T> {
// It should only ever be called from send_event // It should only ever be called from send_event
fn handle_event(&self, event: Event<'static, T>, control: &mut root::ControlFlow) { fn handle_event(&self, event: Event<'static, T>, control: &mut root::ControlFlow) {
let is_closed = self.is_closed(); let is_closed = self.is_closed();
match *self.0.runner.borrow_mut() { match *self.0.runner.borrow_mut() {
Some(ref mut runner) => { Some(ref mut runner) => {
// An event is being processed, so the runner should be marked busy // An event is being processed, so the runner should be marked busy
@ -227,7 +226,9 @@ impl<T: 'static> Shared<T> {
// If the runner doesn't exist and this method recurses, it will recurse infinitely // If the runner doesn't exist and this method recurses, it will recurse infinitely
if !is_closed && self.0.runner.borrow().is_some() { if !is_closed && self.0.runner.borrow().is_some() {
// Take an event out of the queue and handle it // 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); self.handle_event(event, control);
} }
} }