Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't panic in the GTK idle handler if already borrowed. #1043

Merged
merged 4 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You can find its changes [documented below](#060---2020-06-01).

- macOS: Timers not firing during modal loop. ([#1028] by [@xStrom])
- GTK: Directory selection now properly ignores file filters. ([#957] by [@xStrom])
- GTK: Don't crash when receiving an external command while a file dialog is visible. ([#1043] by [@jneem])

### Visual

Expand Down Expand Up @@ -328,6 +329,7 @@ Last release without a changelog :(
[#1013]: https://github.com/xi-editor/druid/pull/1013
[#1028]: https://github.com/xi-editor/druid/pull/1028
[#1042]: https://github.com/xi-editor/druid/pull/1042
[#1043]: https://github.com/xi-editor/druid/pull/1043

[Unreleased]: https://github.com/xi-editor/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/xi-editor/druid/compare/v0.5.0...v0.6.0
Expand Down
21 changes: 14 additions & 7 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,15 +748,22 @@ impl IdleHandle {

fn run_idle(state: &Arc<WindowState>) -> glib::source::Continue {
util::assert_main_thread();
let mut handler = state.handler.borrow_mut();
if let Ok(mut handler) = state.handler.try_borrow_mut() {
let queue: Vec<_> = std::mem::replace(&mut state.idle_queue.lock().unwrap(), Vec::new());

let queue: Vec<_> = std::mem::replace(&mut state.idle_queue.lock().unwrap(), Vec::new());

for item in queue {
match item {
IdleKind::Callback(it) => it.call(handler.as_any()),
IdleKind::Token(it) => handler.idle(it),
for item in queue {
match item {
IdleKind::Callback(it) => it.call(handler.as_any()),
IdleKind::Token(it) => handler.idle(it),
}
}
} else {
log::warn!("Delaying idle callbacks because the handler is borrowed.");
// Keep trying to reschedule this idle callback, because we haven't had a chance
// to empty the idle queue. Returning glib::source::Continue(true) achieves this but
// causes 100% CPU usage, apparently because glib likes to call us back very quickly.
let state = Arc::clone(state);
glib::timeout_add(16, move || run_idle(&state));
}
glib::source::Continue(false)
}
Expand Down