From 2f70eb2824852ff9012842bfa9b5ac42a02dd151 Mon Sep 17 00:00:00 2001 From: Antoine Aflalo Date: Mon, 8 Aug 2022 13:11:40 -0400 Subject: [PATCH] fix(Collection): Remove properly device when unselected from the list. Fixes #978 --- .../Framework/Audio/Collection/DeviceCollection.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SoundSwitch.Common/Framework/Audio/Collection/DeviceCollection.cs b/SoundSwitch.Common/Framework/Audio/Collection/DeviceCollection.cs index 95031db401..97a42872cb 100644 --- a/SoundSwitch.Common/Framework/Audio/Collection/DeviceCollection.cs +++ b/SoundSwitch.Common/Framework/Audio/Collection/DeviceCollection.cs @@ -76,7 +76,14 @@ public bool Remove(T item) } var removeId = _byId.Remove(item.Id); - var removeName = _byName.Remove(item.NameClean); + var removeName = _byName.Remove(item.NameClean, out var removedByName); + + //If we found it by name, remove it also with it's id + //this avoid the case that a device is removed because of name matching + //but it's still used since we iterate the _byId + if(removeName) { + _byId.Remove(removedByName.Id); + } return removeId || removeName; }