Skip to content

Commit

Permalink
Fix event loop on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngo Iok Ui committed May 17, 2021
1 parent 78f16f7 commit 12d7ccb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changes/loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tao": patch
---

Fix panic from borrowing in event loop on linux.

31 changes: 10 additions & 21 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,34 +592,23 @@ impl<T: 'static> EventLoop<T> {
});

// Event control flow
let event_queue = Rc::new(RefCell::new(Vec::new()));
let event_queue_ = event_queue.clone();
let keep_running_ = keep_running.clone();
event_rx.attach(Some(&context), move |event| {
event_queue_.borrow_mut().push(event);
Continue(true)
});
context.pop_thread_default();

while *keep_running.borrow() {
gtk::main_iteration();

let mut events = event_queue.borrow_mut();
if !events.is_empty() {
for event in events.drain(..) {
callback(event, &window_target, &mut control_flow);
}
callback(Event::MainEventsCleared, &window_target, &mut control_flow)
}
callback(event, &window_target, &mut control_flow);

match control_flow {
ControlFlow::Exit => {
keep_running.replace(false);
keep_running_.replace(false);
}
ControlFlow::Poll => callback(Event::MainEventsCleared, &window_target, &mut control_flow),
// TODO WaitUntil
_ => (),
_ => {}
}
Continue(true)
});

while *keep_running.borrow() {
gtk::main_iteration();
}
context.pop_thread_default();
}

#[inline]
Expand Down

0 comments on commit 12d7ccb

Please sign in to comment.