From 46eed3591d8363ed14ea28f7d14333bb7132daf9 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 28 Nov 2026 23:56:25 +0000 Subject: [PATCH 1/2] control: test that a request arriving in a frame that runs twice is answered Requests are taken once a frame, in raw_input_hook. One that arrives after that drain, in a frame whose first pass is discarded, has only the transport's wake, which eframe drops as more than one pass old. The trial runs frames as eframe does, one per kept wake, and needs the framework's ControlChannel::poll_input to ask for the next frame while a request waits. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/control.rs | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 76302671d..8ac0bb3a0 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -1094,6 +1094,62 @@ mod tests { Ok(()) } + /// Sends its request as the first pass of the next frame begins, and runs that frame twice: the request arrives + /// after the frame took its requests, and the transport's wake went to the first pass. + struct ArriveInRerunFrame(Option<(mpsc::Sender, ControlRequest)>); + + impl egui::Plugin for ArriveInRerunFrame { + fn debug_name(&self) -> &'static str { + "control request arriving in a rerun frame" + } + + fn on_begin_pass(&mut self, ui: &mut egui::Ui) { + if let Some((sender, request)) = self.0.take() { + let _ = sender.send(request); + ui.ctx().request_discard("a request arriving in a frame that runs twice"); + } + } + } + + /// A request that arrives after the frame took its requests, in a frame that runs twice, is answered by a window at + /// rest: eframe runs a frame only for a wake at most one pass old, so the frame that left the request waiting asks + /// for the next one itself. + #[test] + fn a_request_arriving_in_a_frame_that_runs_twice_is_answered() -> Result<(), Box> { + let (sender, receiver) = mpsc::channel(); + let mut session = deckcraft_engine::Session::with_new(); + deckcraft_engine::sample::open_sample(&mut session)?; + let mut harness = harness_with( + session, + crate::Services::default(), + egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0), + |platform| platform.control = Some(ControlChannel::new(receiver)), + ); + harness.run_steps(30); + let wakes = Arc::new(std::sync::Mutex::new(Vec::new())); + let sink = wakes.clone(); + harness.ctx.set_request_repaint_callback(move |info| { + if let Ok(mut wakes) = sink.lock() { + wakes.push(info.current_cumulative_pass_nr); + } + }); + let (request, reply) = ControlRequest::new("ui.inspect", json!({})); + harness.ctx.add_plugin(ArriveInRerunFrame(Some((sender.clone(), request)))); + // The frames eframe runs: the one the transport's wake started, then one for each wake it keeps. + for _ in 0..30 { + harness.step(); + if let Ok(answer) = reply.try_recv() { + assert_eq!(answer["ok"], true, "{answer}"); + return Ok(()); + } + let now = harness.ctx.cumulative_pass_nr(); + if !wakes.lock().map_err(|_| "wakes")?.drain(..).any(|nr| now <= nr + 1) { + break; + } + } + Err("the request was left waiting with no frame to take it".into()) + } + /// A pass shows the command states of every request taken before it: a diagram inserted in the same frame as the /// switch to its tab leaves Change Colors enabled there, and a labelled click opens its colour menu. #[test] From b760926b00c4157b57753261e674065e8dea8387 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 00:17:16 +0000 Subject: [PATCH 2/2] control: keep painting while an issued screenshot awaits its image The renderer reads a capture back as it submits a later frame, and a slow device (llvmpipe) may not have finished by the frame the issue asked for. The window asked for frames only while a capture was unissued, so an idle window (a paused GIF) drew no more and ui.screenshot got no reply in 60 s. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/app/control.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index e356112bc..77b4ec1f8 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -41,8 +41,9 @@ impl SlideApp { channel.captures.note_pass(); let finished = channel.captures.issue(&host, craft::ui::runtime::motion::now(), document); control::finish_captures(self, &mut channel, finished); - // A capture settles over passes and waits out its delay; an idle window would draw no more of them. - if channel.captures.any_unissued() { + // A capture settles over passes and waits out its delay, and the renderer reads an issued one back as it submits + // a later frame; an idle window would draw no more of them. + if channel.captures.any_unissued() || channel.captures.any_pending() { ui.ctx().request_repaint(); } self.control = Some(channel);