Skip to content

Windows: High CPU Usage when not visible #7776

@Kyryh

Description

@Kyryh

Describe the bug
When not visible (by sending the egui::ViewportCommand::Visible(false) command) a simple egui application will use ~16% CPU on my CPU while using 0% otherwise

To Reproduce
Steps to reproduce the behavior:

  1. Take the following egui application:
use eframe::egui;

fn main() -> Result<(), eframe::Error> {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
        ..Default::default()
    };

    eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.heading("My egui Application");
            if ui.button("Make invisible").clicked() {
                ctx.send_viewport_cmd(egui::ViewportCommand::Visible(false));
            }
        });
    })
}
  1. Run it
  2. Observe CPU usage while open, if the mouse cursor is not in the window or the window is minimized it will drop to 0
  3. Press the button to make the window invisible
  4. CPU usage will go up a lot

Expected behavior
CPU usage should stay low, similar to when it's minimized

Screenshots

Normally
Image
When invisible
Image

Desktop

  • OS: Windows 11 26H1 (28000.1340)
  • Version: eframe 0.33.3, also tested on latest master (bfaf1b4)

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions