Fix negative duration panic on macos (#475)
* Fix negative duration panic on macos
* apply suggestions from code review
* Add a comment explaining condition
---------
Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs
index 72b433c..2b788e3 100644
--- a/examples/with_winit/src/stats.rs
+++ b/examples/with_winit/src/stats.rs
@@ -384,11 +384,24 @@
let text_size = (text_height * 0.9) as f32;
// Text is specified by the baseline, but the y positions all refer to the top of the text
cur_text_y = text_y + text_height;
- let label = format!(
- "{:.2?} - {:.30}",
- Duration::from_secs_f64(this_time),
- profile.label
- );
+ let label = {
+ // Sometimes, the duration turns out to be negative
+ // We have not yet debugged this, but display the absolute value in that case
+ // see https://github.com/linebender/vello/pull/475 for more
+ if this_time < 0.0 {
+ format!(
+ "-{:.2?}(!!) - {:.30}",
+ Duration::from_secs_f64(this_time.abs()),
+ profile.label
+ )
+ } else {
+ format!(
+ "{:.2?} - {:.30}",
+ Duration::from_secs_f64(this_time),
+ profile.label
+ )
+ }
+ };
scene.fill(
Fill::NonZero,
offset,