glutin
glutin copied to clipboard
On MacOS dragging window lags if rendering continuously with Magnet utility enabled and VSync enabled
When rerendering continuously on MacOS 10.15.6 (with VSync enabled) if I try to drag the titlebar to move the window there is an approximately half second to a second delay before the window snaps to the mouse cursor and moves smoothly again.
This small example program reproduces the issue:
(the below code can also be downloaded as a crate from this repository: https://github.com/kettle11/glutin_bug_test)
use glow::*;
use glutin::event::Event;
use glutin::event_loop::{ControlFlow, EventLoop};
use glutin::window::WindowBuilder;
use glutin::ContextBuilder;
fn main() {
let event_loop = EventLoop::new();
let wb = WindowBuilder::new().with_title("A fantastic window!");
let windowed_context = ContextBuilder::new()
.with_vsync(true)
.build_windowed(wb, &event_loop)
.unwrap();
let windowed_context = unsafe { windowed_context.make_current().unwrap() };
let gl =
glow::Context::from_loader_function(|s| windowed_context.get_proc_address(s) as *const _);
unsafe {
gl.clear_color(0.1, 0.2, 0.3, 1.0);
}
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::RedrawRequested(_) => {
unsafe {
gl.clear(glow::COLOR_BUFFER_BIT);
}
windowed_context.swap_buffers().unwrap();
windowed_context.window().request_redraw();
}
Event::LoopDestroyed => {
return;
}
_ => (),
}
});
}
Some additional interesting details:
This bug also occurs if the line:
windowed_context.swap_buffers().unwrap();
is replaced with:
std::thread::sleep(std::time::Duration::from_millis(16));
which indicates to me that perhaps "RedrawRequested" is issued in a call that MacOS does not expect to take long.
I managed to reproduce the same behavior for SDL as well, and for the Unity game RimWorld (I don't know how Unity handles windowing internally). It did not occur for Factorio and some other games I tested. It does not seem to occur for most apps that don't rerender continuously.
Oddly when I record a fullscreen video what I see and what the video records are different. In the video the mouse cursor always appears to be snapped to the window titlebar even though the window itself clearly lags, but what I see is the mouse moving ahead of the window and then the window eventually catching up.
This also seems like it may be an issue for Metal windows as well, which I have been trying to get working on a crate I've been working on.
I'm very curious if other people run into this issue as well.