Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop): cap mic volume meter window against frozen capture clocks

Richie McIlroya2f4eadd1c6e
diff --git a/apps/desktop/src-tauri/src/audio_meter.rs b/apps/desktop/src-tauri/src/audio_meter.rs
index c383f3751..8070eb9e9 100644
--- a/apps/desktop/src-tauri/src/audio_meter.rs
+++ b/apps/desktop/src-tauri/src/audio_meter.rs
@@ -56,6 +56,22 @@ impl VolumeMeter {
self.maxes.push(time, value);
self.times.push_back(time);
+ // The duration-window eviction below stalls permanently when a
+ // device's capture clock is frozen or non-monotonic (duration_since
+ // yields Zero forever or None), and this meter lives for the whole
+ // process; without a hard cap it grows one entry per audio callback
+ // until quit.
+ const MAX_WINDOW_ENTRIES: usize = 512;
+ while self.times.len() > MAX_WINDOW_ENTRIES {
+ // A frozen clock produces duplicate keys that share one `maxes`
+ // entry; only drop that entry once no duplicate remains queued.
+ if let Some(front) = self.times.pop_front()
+ && !self.times.contains(&front)
+ {
+ self.maxes.remove(&front);
+ }
+ }
+
while let Some(time) = self
.times
.back()