Skip to content

Commit

Permalink
Fix negative duration panic on macos (#475)
Browse files Browse the repository at this point in the history
* Fix negative duration panic on macos

* apply suggestions from code review

* Add a comment explaining condition

---------

Co-authored-by: Daniel McNab <[email protected]>
  • Loading branch information
Enter-tainer and DJMcNab authored Mar 4, 2024
1 parent e8456db commit 387c7be
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions examples/with_winit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,24 @@ pub fn draw_gpu_profiling(
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,
Expand Down

0 comments on commit 387c7be

Please sign in to comment.