Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Window.redraw_window() can cause the window to seemingly "destroy and recreate" itself intermittently on Windows 10 #1477

Closed
maroider opened this issue Feb 21, 2020 · 11 comments · Fixed by #1496
Labels
C - needs investigation Issue must be confirmed and researched DS - windows

Comments

@maroider
Copy link
Member

If my program calls redraw_window() inside the MainEventsCleared event and I hold my mouse still and don't use my keyboard, the window's decorations will briefly light up as if hovered over and then go back to normal. This happens intermittently. The window's task bar icon will also disappear and reappear at the same time the window decorations blink.

Here is a video demonstrating the bug.
The following is the code used in the video:

use winit::{
    event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

fn main() {
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new()
        .with_title("A Buggy Window")
        .build(&event_loop)
        .unwrap();
    let mut bug = false;
    event_loop.run(move |event, _, control_flow| match event {
        Event::WindowEvent {
            event: WindowEvent::CloseRequested,
            ..
        } => *control_flow = ControlFlow::Exit,
        Event::DeviceEvent {
            event:
                DeviceEvent::Key(KeyboardInput {
                    virtual_keycode: Some(VirtualKeyCode::B),
                    state: ElementState::Pressed,
                    ..
                }),
            ..
        } => {
            bug = !bug;
            if bug {
                println!("bug enabled");
            } else {
                println!("bug disabled");
            }
        }
        Event::MainEventsCleared => {
            if bug {
                window.request_redraw();
            }
        }
        _ => {}
    })
}

I've managed to get the bug to appear on both winit = 0.21.0 and on the master branch (9999f53).

@ryanisaacg ryanisaacg added DS - windows C - needs investigation Issue must be confirmed and researched labels Mar 3, 2020
@filnet
Copy link
Contributor

filnet commented Mar 8, 2020

We have pushed a number of critical fixes for Windows.
Please retest on master.

@maroider
Copy link
Member Author

maroider commented Mar 8, 2020

The issue persists as of e85a80d. I couldn't reproduce the issue with the window focused, but I had the same issue with 9999f53. It seems like the blinking is dependent upon some unknown outside factor.

@filnet
Copy link
Contributor

filnet commented Mar 8, 2020

I have reproduced a similar issue.
Every ~5 seconds the title bar briefly flashes the (Not responding) and the X button highlights.

Could be related to this : https://superuser.com/questions/961843/how-does-windows-know-if-a-program-is-not-responding/961910

@maroider
Copy link
Member Author

maroider commented Mar 9, 2020

It feels strange to me that that would be the root cause, but I have no idea how winit's back-end polls the window's event queue, so I can't say anything definitive. I might do some more detective work this week if time permits.

@filnet
Copy link
Contributor

filnet commented Mar 9, 2020

Yes, it is strange as we do call PeekMessage for every event loop iteration in Poll mode.
But it really looks like Windows is considering that the app is hung.

At first I though it could be caused by the event loop running at full speed but adding a sleep to throttle it does not remove the issue.

Poll mode calls only PeekMessage while the other modes will call GetMessage or MsgWaitForMultipleObjectsEx.
But we are calling PeekMessage with a null HWND. Could that be the cause ?

@filnet
Copy link
Contributor

filnet commented Mar 9, 2020

And I can't reproduce it on Windows 7.

@filnet
Copy link
Contributor

filnet commented Mar 9, 2020

On Windows 10, the Task manager will show that the application is "not responding" when not moving the mouse or triggering any kind of event.
image

@maroider can you confirm the same ?

Edit: and this happens in Poll mode and only if request_redraw is called.

@Osspial
Copy link
Contributor

Osspial commented Mar 9, 2020

I tested this on my machine and it looks like #1496 fixes this issue.

@maroider
Copy link
Member Author

@filnet I haven't observed any "not responding" warnings in either the window's title bar or task manager.

@Osspial I ran the bug-inducing code against your PR and let it sit for a couple of minutes. I could not observe the bug. It does indeed seem like #1496 inadvertently fixes it.

@filnet
Copy link
Contributor

filnet commented Mar 10, 2020

I was not able to reproduce the issue with #1496

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - needs investigation Issue must be confirmed and researched DS - windows
Development

Successfully merging a pull request may close this issue.

4 participants