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)
This commit is contained in:
parent
595e49c997
commit
82e7cd814a
1 changed files with 4 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue