Skip to content

Commit afd8794

Browse files
committed
fix(example): handle NaN in waveform peak calculation
Use fold with f32::max instead of max_by with partial_cmp to avoid panic when audio samples contain NaN values.
1 parent a20f869 commit afd8794

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

examples/16_full_metal_app/waveform.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ impl WaveformBuffer {
7373
let start = (self.write_pos + self.samples.len() - count) % self.samples.len();
7474
(0..count)
7575
.map(|i| self.samples[(start + i) % self.samples.len()].abs())
76-
.max_by(|a, b| a.partial_cmp(b).unwrap())
77-
.unwrap_or(0.0)
76+
.fold(0.0_f32, f32::max)
7877
}
7978
}

0 commit comments

Comments
 (0)