You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But there is a case in which it can block in wayland, and that is if the control flow is set to Wait and there are no events
Here is a simple reproduction, there are 3 XXX comments that explains my findings
fnmain() -> std::process::ExitCode{use std::process::ExitCode;use std::thread::sleep;use std::time::Duration;use winit::application::ApplicationHandler;use winit::event::WindowEvent;use winit::event_loop::{ActiveEventLoop,ControlFlow,EventLoop};use winit::platform::pump_events::{EventLoopExtPumpEvents,PumpStatus};use winit::window::{Window,WindowId};#[derive(Default)]structPumpDemo{window:Option<Window>,}implApplicationHandlerforPumpDemo{fnresumed(&mutself,event_loop:&ActiveEventLoop){let window_attributes = Window::default_attributes().with_title("A fantastic window!");self.window = Some(event_loop.create_window(window_attributes).unwrap());}fnwindow_event(&mutself,event_loop:&ActiveEventLoop,_window_id:WindowId,event:WindowEvent,){println!("{event:?}");let window = matchself.window.as_ref(){Some(window) => window,None => return,};match event {WindowEvent::CloseRequested => event_loop.exit(),WindowEvent::RedrawRequested => {// XXX: If I uncomment this the event loop will continue working regardless of ControlFlow// window.request_redraw();}
_ => (),}}}letmut event_loop = EventLoop::new().unwrap();// XXX With Wait the event loop gets blocked unless I uncomment window redraw// If I change it to Poll the event loop never gets blocked even without redraw requests// In X11 even with Wait and no redraw requests, the event loop does not get blocked
event_loop.set_control_flow(ControlFlow::Wait);letmut app = PumpDemo::default();loop{let timeout = Some(Duration::ZERO);// XXX: the block happen herelet status = event_loop.pump_app_events(timeout,&mut app);ifletPumpStatus::Exit(exit_code) = status {breakExitCode::from(exit_code asu8);}println!("Update()");sleep(Duration::from_millis(16));}}
I'd generally suggest to not use Wait with pump_events unless you know what you're doing, so not doing so would also help.
winit generally should just ignore control_flow entirely when this specific API is used, right now you have 2 of them interact in a bad way, since Wait + timeout is generally a WaitUntil, however in this case it just breaks, because it thinks that normal Wait is what was used.
X11 should generally be also affected, you just get lucky that it doesn't.
Thanks @kchibisov for the quick response. @sigmaSd this suggests that we should use Poll when calling pump_events, which is in line with your observations, I think.
Description
The docs of pump_events says it will never block if the timeout is 0
But there is a case in which it can block in wayland, and that is if the control flow is set to Wait and there are no events
Here is a simple reproduction, there are 3 XXX comments that explains my findings
I reached here while debugging slint-ui/slint#7657
Window isn't shown unless you draw
Winit version
0.30.9
The text was updated successfully, but these errors were encountered: