diff --git a/crates/ui-contract/src/contract/lazy.rs b/crates/ui-contract/src/contract/lazy.rs index 699ec1f575..373d04a52e 100644 --- a/crates/ui-contract/src/contract/lazy.rs +++ b/crates/ui-contract/src/contract/lazy.rs @@ -234,10 +234,11 @@ struct Audited<'a> { shift: egui::RecordShift, } -/// Whether the replay audit runs a child that would replay in a pass whose runs are `real` (test builds only). +/// Whether the replay audit runs a child that would replay in a pass whose runs are `real` (test builds only). A pass +/// egui will discard paints nothing, so a run there is no shown run to compare with: the child replays. fn audits(ctx: &egui::Context, real: bool) -> bool { #[cfg(feature = "testing")] - return real && crate::runtime::audit::runs(ctx); + return real && !ctx.will_discard() && crate::runtime::audit::runs(ctx); #[cfg(not(feature = "testing"))] { let _ = (ctx, real); diff --git a/crates/ui-contract/src/runtime/audit.rs b/crates/ui-contract/src/runtime/audit.rs index 5570ef382e..f55aad6e10 100644 --- a/crates/ui-contract/src/runtime/audit.rs +++ b/crates/ui-contract/src/runtime/audit.rs @@ -3,6 +3,9 @@ //! naming the view and the first difference of each kind: a replay that differs from a real run is a view whose props //! miss an input, or a registration the journal misses. //! +//! A pass egui will discard paints nothing and keeps no record (`lazy::ran`): the audit skips it, and a view there +//! replays. +//! //! The audit run keeps the kept run as it was, so every later pass compares with what a replay adds, and every decision //! is the one the pass makes with the audit off. Only the outermost view that would replay runs: a view that would //! replay inside an audit run replays, and the outer comparison covers that replay. The count trials' counters count diff --git a/crates/ui-contract/src/runtime/lazy.rs b/crates/ui-contract/src/runtime/lazy.rs index 9fb761b2b6..449bfeee9d 100644 --- a/crates/ui-contract/src/runtime/lazy.rs +++ b/crates/ui-contract/src/runtime/lazy.rs @@ -554,6 +554,10 @@ pub(crate) fn audit( same: Option, shift: &RecordShift, ) { + // A pass that turned to discard during the audit run paints nothing: its run is no shown run to compare with. + if ctx.will_discard() { + return; + } let Some(kept) = with(ctx, |store, _, _| store.entries.get(&id).and_then(|entry| entry.settled.clone())) else { return }; let kept_run = crate::runtime::audit::Shown { record: &kept.record, rect: kept.rect, output: kept.output.as_ref() }; crate::runtime::audit::compare(name, id, (kept_run, shift), run, same); @@ -587,8 +591,13 @@ pub(crate) struct Ran { pub(crate) output: Option, } -/// Keeps the real run `record` of the memoized view `id`, which ran at `place` and took `rect`. +/// Keeps the real run `record` of the memoized view `id`, which ran at `place` and took `rect`. A run in a pass egui +/// will discard keeps none: egui paints nothing of that pass (`Painter::is_visible` is false in it), so the run registers +/// invisible widgets and no nodes, which a shown pass's replay must not add. The kept record stays the last shown pass's. pub(crate) fn ran(ctx: &Context, id: Id, record: Record, place: Place, rect: Rect, Ran { key, edits, seen, view, output }: Ran) { + if ctx.will_discard() { + return; + } let targets = focus::targets(ctx); let engaged_now = record.focus.stop_ids().any(|stop| targets.contains(&Some(stop))); let lives = crate::runtime::memory::ended_generation(ctx); diff --git a/crates/ui-widgets/tests/it/body/memo_view.rs b/crates/ui-widgets/tests/it/body/memo_view.rs index bba3f142cc..04c464b555 100644 --- a/crates/ui-widgets/tests/it/body/memo_view.rs +++ b/crates/ui-widgets/tests/it/body/memo_view.rs @@ -206,6 +206,32 @@ fn a_changed_prop_runs_its_view_once() { assert_eq!(scene.out, run, "a replay returns what the run returned"); } +/// A pass egui will discard paints nothing, so a run there keeps no record: a settled view replays through it, and the +/// replay audit runs nothing in it; a view whose props change in it runs there and again in the shown pass, whose run +/// is the one kept. The audit is on, so each later replay is compared with a real run. +#[trial] +fn a_pass_egui_will_discard_keeps_no_record_and_replays_settled_views() { + let mut frames = Frames::new(); + craft_ui::testing::audit_replays(&frames.ctx, true); + let frame = |frames: &mut Frames, shown: &str, discard: bool| { + let passes = frames.frame(vec![], |ui| { + if discard && ui.ctx().current_pass_index() == 0 { + frame::discard_pass(ui.ctx(), "trial"); + } + in_region(ui, region(0), |ui| MemoView::new("title", Title { title: shown.to_owned() }, title).show(ui)); + }); + (passes, title_runs()) + }; + for _ in 0..WARM { + frame(&mut frames, "A", false); + } + assert_eq!(frame(&mut frames, "A", false), (1, 0), "a settled view replays"); + assert_eq!(frame(&mut frames, "A", true), (2, 0), "it replays through the discarded pass and the shown one"); + assert_eq!(frame(&mut frames, "A", false), (1, 0), "its kept record is unchanged: a run gives what it replays"); + assert_eq!(frame(&mut frames, "B", true), (2, 2), "new props run it in the discarded pass and again in the shown one"); + assert_eq!(frame(&mut frames, "B", false), (1, 0), "then it replays the shown pass's run"); +} + /// A view that writes its own `&mut Tracked` runs twice for the change that asked for the write, the writing run and /// one that reads the written value, then replays. #[trial]