From 6039916631c0767348711257bb6cd10deb6e7178 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 19 Oct 2021 17:25:08 -0700 Subject: [PATCH] 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. --- piet-gpu/bin/winit.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/piet-gpu/bin/winit.rs b/piet-gpu/bin/winit.rs index c5f9bef..19db3c2 100644 --- a/piet-gpu/bin/winit.rs +++ b/piet-gpu/bin/winit.rs @@ -1,4 +1,3 @@ -use piet::RenderContext; use piet_gpu_hal::{Error, ImageLayout, Instance, Session, SubmittedCmdBuf}; use piet_gpu::{test_scenes, PietGpuRenderContext, Renderer}; @@ -152,6 +151,13 @@ fn main() -> Result<(), Error> { 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(); + } + } _ => (), } })