From 82e7cd814addb0641959b634227fe550374e195b Mon Sep 17 00:00:00 2001 From: agrimkasaju Date: Sun, 20 Sep 2026 15:10:58 -0400 Subject: [PATCH] fix(audio): adjust active device index on node removal When an audio device preceding the active sink or source is removed, the internal vector elements shift left, but self.active was not decremented. Subsequent volume or mute events accessed an out-of-bounds index, causing an immediate panic: thread 'main' panicked at cosmic-applet-audio/src/model.rs:116:64: index out of bounds: the len is 6 but the index is 6 Fix by decrementing self.active when active > pos in Nodes::remove. Fixes #1508 Assisted-by: AI (Google Antigravity) --- cosmic-applet-audio/src/model.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cosmic-applet-audio/src/model.rs b/cosmic-applet-audio/src/model.rs index 42c76b3c..5aff7ba4 100644 --- a/cosmic-applet-audio/src/model.rs +++ b/cosmic-applet-audio/src/model.rs @@ -74,8 +74,10 @@ impl Nodes { self.id.remove(pos); self.volume.remove(pos); self.dropdown_sort(); - if self.active == Some(pos) { - self.active = None; + match self.active { + Some(active) if active == pos => self.active = None, + Some(active) if active > pos => self.active = Some(active - 1), + _ => {} } true }