mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-14 05:24:44 +00:00
Fix #7093: the font menu tests draw until every shown sample is rendered
open_menu_with waited once for the samples rendering and then drew its last frame. A frame starts at most four samples, and none while eight are rendering, so that last frame could start the samples of the rows it showed instead of drawing them, and show_samples_on_white_draws_dark_type_on_white_in_every_brightness failed with "dark: samples are drawn" when the workers were slow. wait_for_samples now returns whether any sample was rendering, and the helper draws and waits until a frame leaves none rendering. Only test code changes: wait_for_samples is cfg(test) and open_menu_with is a test helper. Diagnosis and approach by Taha-Mahmoodi in #7093.
This commit is contained in:
@@ -1642,18 +1642,20 @@ pub(crate) fn render_sample_for_test(family: &str, text: &str, px: u32) -> Optio
|
||||
}
|
||||
|
||||
/// Waits for the samples rendering on this thread's behalf and keeps them, so the next frame
|
||||
/// draws them.
|
||||
/// draws them. Returns `false` when no sample was rendering.
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
pub(crate) fn wait_for_samples(ctx: &egui::Context) {
|
||||
pub(crate) fn wait_for_samples(ctx: &egui::Context) -> bool {
|
||||
SAMPLES.with(|s| {
|
||||
let mut s = s.borrow_mut();
|
||||
let pending: Vec<_> = s.pending.drain().collect();
|
||||
let waited = !pending.is_empty();
|
||||
for (key, rx) in pending {
|
||||
let tex =
|
||||
rx.recv().ok().flatten().map(|img| ctx.load_texture(format!("font-sample-{}-{}", key.0, key.3), img, egui::TextureOptions::LINEAR));
|
||||
s.ready.insert(key, tex);
|
||||
}
|
||||
});
|
||||
waited
|
||||
})
|
||||
}
|
||||
|
||||
// ---------- applying a pick ----------
|
||||
|
||||
@@ -1031,8 +1031,15 @@ fn open_menu_with(id: &str, left: f32, width: f32, screen: egui::Vec2, look: Men
|
||||
for _ in 0..if tokens.is_some() { 15 } else { 5 } {
|
||||
frame(vec![]);
|
||||
}
|
||||
crate::font_menu::wait_for_samples(&ctx);
|
||||
let shapes = frame(vec![]);
|
||||
// A frame starts only a few samples, and none while several are rendering: draw until a frame
|
||||
// leaves none rendering, so that frame drew every shown row's sample.
|
||||
let mut shapes = frame(vec![]);
|
||||
let mut frames = 0;
|
||||
while crate::font_menu::wait_for_samples(&ctx) {
|
||||
frames += 1;
|
||||
assert!(frames < 1000, "the menu's samples are still rendering after {frames} frames");
|
||||
shapes = frame(vec![]);
|
||||
}
|
||||
let mut texts = vec![];
|
||||
let mut samples = vec![];
|
||||
let mut tints = vec![];
|
||||
|
||||
Reference in New Issue
Block a user