-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Duration passed to request_repaint_after
is ignored if called each frame
#3109
Comments
have the same problem in my app https://github.com/chrisheib/STStat I'll downgrade for the time being, can't let my users waste their ressources like this. |
If you run with Most of the logic can be found in |
I tried your code on my Mac on latest The results is as expected: High FPS when moving the mouse over the window, and 1 fps when the mouse is still or outside the egui window. The behavior is the same if the windows is in focus or in the background. Can you please try again on latest |
I'm seeing this bug on Windows as well with latest master. I'll take a look and see if I can figure anything out. |
Alright - I understand why this is happening in the current code and have a possible (though dubious) fix in mind. I didn't run the code before the commit that introduced this (834e2e9) to figure out why it wasn't happening previously. The workaround on this line is at least partially to blame. When there's a This bug only happens when the There's another bug confusing things here - the I have two very dubious fixes and some unpolished tweaks to the demo app for testing this in #3275. I removed the workaround and allowed off-by-one for the frame number. Neither seems like a real fix. With these changes, calling I'm looking for suggestions of what the proper fix(es) might be - I don't think what I've done in my PR are adequate or correct. |
Thanks for the investigation! I’m hoping we can remove the windows-hack when the new winit version drops, which should be any week now 🤞 The new winit has a substantially new event-loop |
Hi, I stumbled upon this on accident, when I noticed adding |
Here's my clunky temporary solution - just spin up another thread that sleeps and occasionally calls |
This is also happening on Linux on Wayland after I upgraded eframe from 0.23.0 to 0.24.1 |
Likewise here, macOS. @OmegaJak's fix is a great tip, though 👍 |
Actually for those also running on the web, you'll need a non-std::thread implementation. Here's an analog to the above using weird wasm/async stuff (I already had these specific crates hanging around, there might be better options here 🤷): Loop (using gloo-timers): // TODO: Once https://github.com/emilk/egui/issues/3109 is resolved, use request_repaint_after in main loop instead
#[cfg(target_arch = "wasm32")]
pub async fn create_periodic_repaint_async(
egui_ctx: egui::Context,
millis_between_repaints: u32,
) {
loop {
egui_ctx.request_repaint();
gloo_timers::future::TimeoutFuture::new(millis_between_repaints).await;
}
} Setup inside the creation context (using wasm-bindgen-futures): // TODO: Once https://github.com/emilk/egui/issues/3109 is resolved, use request_repaint_after in main loop instead
#[cfg(target_arch = "wasm32")]
wasm_bindgen_futures::spawn_local(create_periodic_repaint_async(
cc.egui_ctx.clone(),
)); |
Is this still a problem in egui/eframe (EDIT: version snafu) |
@emilk Could you please elaborate what you mean by egui/eframe 0.18? I believe I am still able to replicate the issue on egui/eframe 0.24.1. |
Yes I only encountered this issue this week after updating from .21.x to .24.x |
I don't know how I miss-typed "0.24" as "0.18", but I did 🤦 |
Adding some more data points. I didn't encounter this issue until after upgrading to 0.24.1 from 0.23 (macOS). I don't have a thorough understanding of the implementation yet but it seems like this is where the https://github.com/emilk/egui/blob/master/crates/egui/src/context.rs#L82 If I add a dummy callback to the egui context then the cc.egui_ctx.set_request_repaint_callback(|_| {}); |
Both glow and wgpu integrations call
I think that's just because you're overriding the integration's callback |
That's right, I read a bit more after my previous comment. Based on the limited time I got to wonder around. It seems like it's somewhere around https://github.com/emilk/egui/blob/master/crates/egui/src/context.rs#L80 and that's causing this issue. I don't know what's behind https://github.com/emilk/egui/blob/master/crates/egui/src/context.rs#L80 so I'm not sure what's the correct and simplest fix that won't change other expected behaviors. But I hope this observation helps. |
request_repaint_after
is ignored on Windows
On a new branch because of emilk/egui#3109
request_repaint_after
is ignored on Windowsrequest_repaint_after
is ignored if called each frame
…nt (emilk#3978) * Closes emilk#3925 * Closes emilk#3109
Describe the bug
Using egui 0.22.0, calling
request_repaint_after()
causes the application to redraw the UI with a high refresh rate, regardless of the duration passed intorequest_repaint_after()
. It behaves (mostly) as if callingrequest_repaint()
.The bug was not there in version 0.21.0.
Steps to reproduce the behavior:
The following code was adapted from the hello world example. I replaced the controls with a fps (frames per second) and counter label. Rust file:
toml:
Build and run on Windows 10.
When the application has focus, the "fps" labels shows approximately a value of 144 on my monitor (which has a refresh rate of 144 Hz), regardless of where the mouse is. When the application does not have focus, the "fps" label continues updating with a high frequency and shows approximately 90. (I have no idea where the 90 is coming from.)
If I remove the call to
request_repaint_after()
, the application no longer updates with a high rate.Keeping the
request_repaint_after()
call and going back to egui 0.21.0, I get the expected behavior. Considering the release notes, I guess this is related to #2939.Expected behavior
When the application does NOT have focus, the "fps" label should show a value of approximately 1. In other words, the GUI should update only once a second because I passed 1s as duration to
request_repaint_after()
.When the application does have focus, the "fps" label should show a value of 144 only while moving around the mouse.
Desktop:
The text was updated successfully, but these errors were encountered: