diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 66c179e50..f443eae14 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -1156,7 +1156,7 @@ mod glow_integration { } else { repaint_after .into_iter() - .map(|(id, time)| { + .flat_map(|(id, time)| { if time.is_zero() { if let Some(id) = window_map.get(&id) { Some(EventResult::RepaintNext(*id)) @@ -1181,7 +1181,6 @@ mod glow_integration { None } }) - .flatten() .collect::>() }; diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 14a9dffe6..e2c58f3e1 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -125,7 +125,11 @@ impl Repaint { } // returns how long to wait until repaint - fn end_frame(&mut self, viewport_id: u64) -> Vec<(u64, std::time::Duration)> { + fn end_frame( + &mut self, + viewport_id: u64, + viewports: Vec, + ) -> Vec<(u64, std::time::Duration)> { // if repaint_requests is greater than zero. just set the duration to zero for immediate // repaint. if there's no repaint requests, then we can use the actual repaint_after instead. let repaint_after = if self.repaint_requests > 0 { @@ -142,6 +146,8 @@ impl Repaint { self.requested_repaint_last_frame = repaint_after.is_zero(); self.frame_nr += 1; + self.repaint_after.retain(|id, _| viewports.contains(id)); + self.repaint_after .iter() .map(|(id, time)| (*id, *time)) @@ -1301,7 +1307,18 @@ impl Context { } } - let repaint_after = self.write(|ctx| ctx.repaint.end_frame(ctx.current_rendering_viewport)); + let mut viewports: Vec = self.read(|ctx| { + ctx.viewports + .iter() + .map(|(_, (_, id, _, _, _))| *id) + .collect() + }); + viewports.push(0); + + let repaint_after = self.write(|ctx| { + ctx.repaint + .end_frame(ctx.current_rendering_viewport, viewports) + }); let shapes = self.drain_paint_lists(); // This is used for,