From cb40855e6ff64ac37a481665471fb32051f5c5f6 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 2 Dec 2026 16:02:35 +0100 Subject: [PATCH] ui: a headless context starts no desktop appearance watcher Every headless egui context (each test app) started a SystemReader with a desktop-appearance worker thread that outlived the test. In a test binary that runs all tests in one process (plain cargo test on FreeBSD), the threads add up until spawning a thread fails with EAGAIN, which failed 81 ui-egui lib tests in the FreeBSD nightly. --- crates/ui-egui/src/app/framework.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/app/framework.rs b/crates/ui-egui/src/app/framework.rs index ea8e63a4868..5d5e738a40f 100644 --- a/crates/ui-egui/src/app/framework.rs +++ b/crates/ui-egui/src/app/framework.rs @@ -74,10 +74,11 @@ pub(crate) fn install(ctx: &egui::Context, fonts: &UiFonts<'_>, frame: Option = if frame.is_some() { Arc::new(Desktop) } else { Arc::new(NoWindows) }; - let mut spec = InstallSpec::new(ShellInfo::default().backend(Backend::from_env()), desktop) - .wheel(wheel) - .app_id(crate::os_window::app_id()) - .system(SystemReader::start(move || wake.request_repaint())); + // The same goes for the OS's appearance: a headless context starts no desktop watcher. Each watcher has a worker + // thread, and a test binary that runs every test in one process (plain `cargo test` on FreeBSD and Windows) would + // otherwise keep one per context until it can spawn no more threads. + let system = if frame.is_some() { SystemReader::start(move || wake.request_repaint()) } else { SystemReader::unwatched() }; + let mut spec = InstallSpec::new(ShellInfo::default().backend(Backend::from_env()), desktop).wheel(wheel).app_id(crate::os_window::app_id()).system(system); if let Some(decision) = frame { spec = spec.frame(decision); }