From bca0b28865da4e99a68a6e3913d6b63bdf59c29a Mon Sep 17 00:00:00 2001 From: AlphaNeon <102443376+ItsAlphaNeon@users.noreply.github.com> Date: Thu, 3 Dec 2026 02:27:49 -0700 Subject: [PATCH 1/2] Command-line render: destroy its plugins before it returns, so a finished render exits 0 lemonstudio --render left the instances it hosted on the retired list, and they were destroyed in the process's exit, after Windows had ended their threads. Citrus joins a thread of its own in its destructor, so a render that had written its WAV aborted with exit code 127. The render now drops its session and sweeps the retired list on its own thread, as the window does at exit. Co-Authored-By: Claude Opus 5.5 --- crates/os-app/src/render.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/os-app/src/render.rs b/crates/os-app/src/render.rs index c2f313833..064e7671b 100644 --- a/crates/os-app/src/render.rs +++ b/crates/os-app/src/render.rs @@ -171,6 +171,11 @@ pub fn render(o: &Opts) -> Result<(), String> { let peak = audio.iter().fold(0.0f32, |m, v| m.max(v.abs())); eprintln!("RENDERED {:.2} s (song {:.2} s) at {} Hz in {:.1} s, peak {peak:.3}", audio.len() as f64 / 2.0 / rate as f64, len as f64 / rate as f64, o.rate, t1.elapsed().as_secs_f64()); crate::project_io::reset_hosted(&mut ses); + // The instances let go are destroyed now, on this thread, as the window does at exit: left on the retired list + // they were destroyed in the process's exit, after Windows had ended their threads, and a plugin that joins a + // thread of its own in its destructor (Citrus) aborted the process: a render that had written its file exited 127. + drop(ses); + crate::plugins::sweep_retired(); written.map_err(|e| format!("{}: {e}", o.out.display())) } @@ -312,6 +317,9 @@ mod tests { let file = os_flp::project::create(&p).expect("create"); std::fs::write(&flp, file.to_bytes().expect("bytes")).unwrap(); render(&Opts { hosted: Hosted::Builtin, seconds: Some(1.5), ..Opts::new(flp, out.clone()) }).expect("render"); + // Its Lemon Sampler is destroyed before the render returns, not left for the process's exit (where a plugin + // that joins its own thread aborted a finished command-line render). + assert_eq!(crate::plugins::retired_count(), 0, "a render destroys the instances it hosted"); let wav = std::fs::read(&out).unwrap(); let at = wav.windows(4).position(|w| w == b"data").expect("data chunk") + 8; From 06d56776bed983c3415a90d1da031badb2626046 Mon Sep 17 00:00:00 2001 From: AlphaNeon <102443376+ItsAlphaNeon@users.noreply.github.com> Date: Thu, 3 Dec 2026 02:34:05 -0700 Subject: [PATCH 2/2] dropout_log test: work until the thread has run 10 ms, not for a fixed 20 ms On a loaded CI runner 20 ms of busy work ran 9.9 ms of CPU and failed a_hold_tells_running_from_waiting (Linux, PR #472). The loop now works until its running time reaches 10 ms, failing only if it never does within 2 s. Co-Authored-By: Claude Opus 5.5 --- crates/os-session/src/dropout_log.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/os-session/src/dropout_log.rs b/crates/os-session/src/dropout_log.rs index 275e5fff5..6d04b0e1e 100644 --- a/crates/os-session/src/dropout_log.rs +++ b/crates/os-session/src/dropout_log.rs @@ -235,11 +235,15 @@ mod tests { let h = Hold::start(); std::thread::sleep(Duration::from_millis(20)); assert!(h.ran().unwrap() < Duration::from_millis(5), "asleep: {:?}", h.ran()); + // Works until it has run 10 ms: a loaded machine (CI) takes the thread off the CPU for part of any fixed span + // (20 ms of work once ran 9.9 ms), so the span is not fixed; a running time that never grows fails at 2 s. let h = Hold::start(); - while h.elapsed() < Duration::from_millis(20) { - std::hint::black_box(0u64); + while h.ran().unwrap() < Duration::from_millis(10) && h.elapsed() < Duration::from_secs(2) { + for _ in 0..1000 { + std::hint::black_box(0u64); + } } - assert!(h.ran().unwrap() >= Duration::from_millis(10), "working: {:?}", h.ran()); + assert!(h.ran().unwrap() >= Duration::from_millis(10), "working: {:?} in {:?}", h.ran(), h.elapsed()); } #[test]