Wait on in-flight command buffers on exit

If there is a command buffer in flight on exit from the winit app, wait
on it so that the resources get destroyed cleanly.

There may be a more aggressive strategy to quick-exit, but this is
probably the most reliable approach and I see it in other code bases.
This commit is contained in:
Raph Levien 2021-10-19 17:25:08 -07:00
parent f73da22a69
commit 6039916631

View file

@ -1,4 +1,3 @@
use piet::RenderContext;
use piet_gpu_hal::{Error, ImageLayout, Instance, Session, SubmittedCmdBuf}; use piet_gpu_hal::{Error, ImageLayout, Instance, Session, SubmittedCmdBuf};
use piet_gpu::{test_scenes, PietGpuRenderContext, Renderer}; use piet_gpu::{test_scenes, PietGpuRenderContext, Renderer};
@ -152,6 +151,13 @@ fn main() -> Result<(), Error> {
current_frame += 1; current_frame += 1;
} }
Event::LoopDestroyed => {
if let Some(submitted) = submitted.take() {
// Wait for command list submission, otherwise dropping of renderer may
// cause validation errors (and possibly crashes).
submitted.wait().unwrap();
}
}
_ => (), _ => (),
} }
}) })