Skip to content

App doesn't update if hidden behind some other application (even tho ctx.request_repaint is called in update) #2944

@zrezke

Description

@zrezke

Describe the bug

When app is hidden behind some other window, it stops updating, even tho request_repaint is called.

To Reproduce
Steps to reproduce the behavior:

  1. Run this small example:
  • Just a hello world with a forced ctx.request_repaint to ensure the app always gets updated
  • Each update it prints Updating: {Instant::now()}
use eframe::egui;
use std::time::Instant;


#[derive(Default)]
struct App {

}

impl eframe::App for App {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        println!("Updating: {:?}", Instant::now());
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.label("Hello world");
        });
        ctx.request_repaint();
    }
}

fn main() {
    let options = eframe::NativeOptions {
        initial_window_size: Some(egui::vec2(320.0, 240.0)),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Box::<App>::default()),
    );
}
  1. Do something that hides the app behind some other window.
  2. In the terminal where you ran the app, you will see no more prints appearing...
  3. Try minimizing the app and prints will work

Expected behavior

App should still be updating as request_repaint is called. The behaviour should be the same as when minimizing the window...

Screenshots

Screencast from 21  04  2023 14_58_31

  • First I minimized the window (Logs are still appearing)
  • Then bring it back to foreground
  • Then clicked vscode to hide the app, this is where the logs stop!

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Browser chrome
  • Version 112.0.5615.121

Additional context
I did some debugging (not a lot) and I saw that in eframe/src/native/run.rs::run_and_exit (:318..:326) the next_repaint_time is set to extremely_far_future() ? Probably has something to do with this?

        *control_flow = if next_repaint_time <= Instant::now() {
            if let Some(window) = winit_app.window() {
                window.request_redraw();
            }
            next_repaint_time = extremely_far_future();
            ControlFlow::Poll
        } else {
            ControlFlow::WaitUntil(next_repaint_time)
        };

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