Skip to content

Commit

Permalink
Use Abortable future for StagingBelt recall with GLib spawning
Browse files Browse the repository at this point in the history
In the original code, it was canceled by dropping the local executor.
We need to do the same here to make destruction work fine.
  • Loading branch information
valpackett committed Nov 13, 2020
1 parent 897c089 commit 249b540
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions wgpu/src/window/compositor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{Backend, Color, Error, Renderer, Settings, Viewport};

use futures::task::SpawnExt;
use futures::future::{AbortHandle, Abortable};
use futures::prelude::*;
use iced_native::{futures, mouse};
use raw_window_handle::HasRawWindowHandle;

Expand All @@ -12,6 +13,7 @@ pub struct Compositor {
device: wgpu::Device,
queue: wgpu::Queue,
staging_belt: wgpu::util::StagingBelt,
belt_emergency_stop: Option<AbortHandle>,
}

impl Compositor {
Expand Down Expand Up @@ -60,6 +62,7 @@ impl Compositor {
device,
queue,
staging_belt,
belt_emergency_stop: None,
})
}

Expand Down Expand Up @@ -168,8 +171,21 @@ impl iced_graphics::window::Compositor for Compositor {
self.queue.submit(Some(encoder.finish()));

// Recall staging buffers
glib::MainContext::default().spawn(self.staging_belt.recall());
let (abort_handle, abort_registration) = AbortHandle::new_pair();
self.belt_emergency_stop = Some(abort_handle);
glib::MainContext::default().spawn(
Abortable::new(self.staging_belt.recall(), abort_registration)
.map(|_| ()),
);

mouse_interaction
}
}

impl Drop for Compositor {
fn drop(&mut self) {
if let Some(abort_handle) = self.belt_emergency_stop.take() {
abort_handle.abort();
}
}
}

0 comments on commit 249b540

Please sign in to comment.