File tree Expand file tree Collapse file tree
crates/processing_glfw/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,6 +73,26 @@ impl Default for AppliedWindow {
7373 }
7474}
7575
76+ /// GLFW reports some recoverable conditions as errors, many times a second.
77+ /// Log each distinct message once, as a warning with an explanation where we
78+ /// have one, instead of panicking or flooding the log.
79+ fn log_glfw_error ( ) -> impl FnMut ( glfw:: Error , String ) + ' static {
80+ let mut seen = std:: collections:: HashSet :: new ( ) ;
81+ move |error, description| {
82+ if !seen. insert ( description. clone ( ) ) {
83+ return ;
84+ }
85+ let hint = if description. contains ( "without screen" ) {
86+ ": a connected display isn't attached to a screen (for example a laptop's \
87+ built-in display with the lid closed). It is ignored and doesn't affect the \
88+ sketch"
89+ } else {
90+ ""
91+ } ;
92+ bevy:: log:: warn!( "GLFW {error:?}: {description}{hint} (further repeats not shown)" ) ;
93+ }
94+ }
95+
7696impl GlfwContext {
7797 pub fn new ( width : u32 , height : u32 , transparent : bool ) -> Result < Self > {
7898 let mut ctx = Self :: init ( ) ?;
@@ -86,7 +106,7 @@ impl GlfwContext {
86106 // Without the menubar GLFW never becomes a foreground (Dock, focus-taking) app on macOS.
87107 glfw:: init_hint ( glfw:: InitHint :: CocoaMenubar ( false ) ) ;
88108 }
89- let glfw = glfw:: init ( glfw :: fail_on_errors ) . unwrap ( ) ;
109+ let glfw = glfw:: init ( log_glfw_error ( ) ) . unwrap ( ) ;
90110 Ok ( Self {
91111 glfw,
92112 windows : Vec :: new ( ) ,
You can’t perform that action at this time.
0 commit comments