diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rs index 1e06e9f1ad..ec0647c0c5 100644 --- a/crates/gpu/src/lib.rs +++ b/crates/gpu/src/lib.rs @@ -349,7 +349,12 @@ pub fn warm_up() { if STARTED.swap(true, Ordering::SeqCst) { return; } - let spawned = std::thread::Builder::new().name("lc-gpu-init".into()).spawn(|| { + let Some(work) = exit::enter() else { + STARTED.store(false, Ordering::SeqCst); + return; + }; + let spawned = std::thread::Builder::new().name("lc-gpu-init".into()).spawn(move || { + let _work = work; loop { let _ = device(); if GPU.get().is_some() || shutting_down() || env_disabled() { diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 29ba1334dc..322270a90e 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -641,7 +641,23 @@ impl LightcraftApp { let idle = lightcraft_engine::gpu::wait_idle(timeout); stopped && idle } +} +/// Dropping the app (including in one-test `nextest` processes that never call [`Self::shutdown`]) +/// must not leave render workers or the GPU warm-up thread inside the driver when the process exits +/// (issue #620). Does not call [`lightcraft_engine::gpu::begin_shutdown`] so multiple tests in one +/// `cargo test` process can still use the GPU afterwards. +impl Drop for LightcraftApp { + fn drop(&mut self) { + #[cfg(not(target_arch = "wasm32"))] + { + self.renderer.shutdown(std::time::Duration::from_secs(30)); + let _ = lightcraft_engine::gpu::wait_idle(std::time::Duration::from_secs(30)); + } + } +} + +impl LightcraftApp { /// Background and queue work. Called before layout on every host pass and, while the window is /// hidden, from `Context::run_logic`. It may read the refreshed viewport fields only: never /// `i.time`, events, keys or dropped files.