rust-windowing/glutin

Opening a glutin window on a monitor other than primary monitor for Windows crashes

ReallySnazzy opened this issue · 12 comments

I've used multiple Rust projects with windowing support and managed to track the issue to Glutin. Some other projects I've tried are Neovide, WezTerm and Alacritty. By running the window example on my secondary monitor, I can get the crash as appears in the attached screenshot. Running from my primary window does not give any issue like this. When I try to close it, I get an error about the window not responding. I'm on Windows 11 64 bit. I am not able to view the console window, since I was having trouble getting the window to open on my secondary monitor while it is enabled. I had to add #![windows_subsystem = "windows"] to the window example to get it to open on my secondary monitor.

example window crash

Also, I don't think this issue is specific to Windows 11. If I remember correctly, then I was having this same issue with the mentioned other projects using Glutin before upgrading to Windows 11 from Windows 10.

Does plain winit work?

Plain Winit seems to work. I am able to resize the window and when I close it I do not get any errors about it not being responsive.

I used the example from their readme with a crate macro to indicate windows subsytem.

#![windows_subsystem = "windows"]
use winit::{
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

fn main() {
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new().build(&event_loop).unwrap();

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;

        match event {
            Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                window_id,
            } if window_id == window.id() => *control_flow = ControlFlow::Exit,
            _ => (),
        }
    });
}

Added some logging to a file. It looks like the last event that's able to fire is Event::RedrawRequested(_).

Dug some more. Looks like it never returns from this function call. Added logs before and after this expression and none of the logs after this were saved.

if gl::SwapBuffers(self.hdc) == 0 {

Potentially related Windows bug? wxWidgets/wxWidgets#18532

Strange thing is that plenty of other applications work when opened from secondary monitor.

I ended up making a personal fork of Neovide to make it launch on my primary monitor. So I'll be using that as a workaround for now. I noticed several other hardware accelerated applications launching on the primary monitor by default. Not sure how common this issue is so I'll leave this issue open in case someone else wants to investigate further.

If you disable vsync does it work? Remove

.set_swap_interval(&gl_context, SwapInterval::Wait(NonZeroU32::new(1).unwrap()))
.

If you disable vsync does it work? Remove

.set_swap_interval(&gl_context, SwapInterval::Wait(NonZeroU32::new(1).unwrap()))

.

Unfortunately, that didn't seem to fix the issue. Still gets stuck on swap_buffers. I tried commenting out this line and the surrounding lines that are commented "Try setting vsync"

Using same displays on a new machine. Seems like the crash is not happening on this new machine. My suspicion is GPU settings, but not sure which setting specifically was responsible. New machine is also Windows 11.

was it a dual GPU system btw? windows could decide to load different drivers based on monitor iirc.

Was a single dedicated 3060TI on previous machine. No integrated graphics on last PC. New one is similar setup with no integrated and a single dedicated 4070TI.