emilk / emilk/egui

Parallel example (hello_world_par) seems to rely on continous repaint, "Main thread" sub-window ignores input when idle

Open
#7,828 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 12h
Merged PRs (30d)
67

Description

**Describe the bug**
When running the parallel hello_world example from "examples\hello_world_par", initially everything looks fine. The two initial background thread sub-windows work and are interactive. However, the "Spawn another thread" button in the "Main thread" sub-window does not react at all (no hover highlight, no click).

After playing around with the code, I found that forcing continous repainting - f.e. with a frame counter - leads to the expected behavior. So my best guess would be that the example relies on continous repainting which isn't guaranteed anymore in the newest versions, regarding this note from the README:

> egui only repaints when there is interaction (e.g. mouse movement) or an animation, so if your app is idle, no CPU is wasted.

Code changes needed for workaround:

```
struct MyApp {
[...]
frame_count: u64, // this
}

[...]

impl MyApp {
fn new() -> Self {
let threads = Vec::with_capacity(3);
let (on_done_tx, on_done_rc) = mpsc::sync_channel(0);

let mut slf = Self {
threads,
on_done_tx,
on_done_rc,
frame_count: 0, // this
};

[...]

impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
self.frame_count += 1; // this

egui::Window::new("Main thread").show(ui.ctx(), |ui| {
ui.label(format!("frames: {}", self.frame_count)); // this

if ui.button("Spawn another thread").clicked() {
self.spawn_thread();
}
});

[...]
````

**To Reproduce**
Steps to reproduce the behavior:
1. Compile and run "hello_world_par" from the examples in release mode ("cargo run --release").
2. Interact with the sub-windows "Background thread X" -> works as expected, buttons are clickable and highlighted on hover
3. Try to interact with the "Spawn another thread" button -> no highlight, not clickable

**Expected behavior**
I'd expect the "Spawn another thread" button to highlight and spawn additional sub-windows, which doesn't happen without the described "continous repaint" workaround.

**Screenshots**
Image

(Note the mouse cursor is hovering "Spawn another thread" button, but it isn't highlighted by a white border)

**Desktop**
- OS: Reproducable under both Windows 11 and Ubuntu 22.04

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.