diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index 651d7a2d..6ec48b5e 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -73,6 +73,26 @@ impl Default for AppliedWindow { } } +/// GLFW reports some recoverable conditions as errors, many times a second. +/// Log each distinct message once, as a warning with an explanation where we +/// have one, instead of panicking or flooding the log. +fn log_glfw_error() -> impl FnMut(glfw::Error, String) + 'static { + let mut seen = std::collections::HashSet::new(); + move |error, description| { + if !seen.insert(description.clone()) { + return; + } + let hint = if description.contains("without screen") { + ": a connected display isn't attached to a screen (for example a laptop's \ + built-in display with the lid closed). It is ignored and doesn't affect the \ + sketch" + } else { + "" + }; + bevy::log::warn!("GLFW {error:?}: {description}{hint} (further repeats not shown)"); + } +} + impl GlfwContext { pub fn new(width: u32, height: u32, transparent: bool) -> Result { let mut ctx = Self::init()?; @@ -86,7 +106,7 @@ impl GlfwContext { // Without the menubar GLFW never becomes a foreground (Dock, focus-taking) app on macOS. glfw::init_hint(glfw::InitHint::CocoaMenubar(false)); } - let glfw = glfw::init(glfw::fail_on_errors).unwrap(); + let glfw = glfw::init(log_glfw_error()).unwrap(); Ok(Self { glfw, windows: Vec::new(),