Skip to content

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

@maroider

Description

@maroider

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C - needs investigationIssue must be confirmed and researchedDS - win32Affects the Win32/Windows backend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions