Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion crates/processing_glfw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let mut ctx = Self::init()?;
Expand All @@ -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(),
Expand Down
Loading