Skip to content

Commit

Permalink
fix(crash): app crashing after disconnect a IMMDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Sep 7, 2024
1 parent 113c2e9 commit addf232
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [Unreleased]
## [Unreleased]
### fix
- app crashing on IMMDevice disconnection.

## [1.10.4]
### enhancements
- clean weg items on load to remove duped items and apps/files that don't exist.
Expand Down
5 changes: 5 additions & 0 deletions src/background/modules/media/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ lazy_static! {
Arc::new(Mutex::new(HashMap::new()));
}

#[derive(Debug)]
enum MediaEvent {
DeviceAdded(String),
DeviceRemoved(String),
Expand Down Expand Up @@ -543,6 +544,10 @@ impl MediaManager {
fn release_device(&mut self, device_id: &str) -> Result<()> {
if let Some((endpoint, callback)) = self.devices_audio_endpoint.remove(device_id) {
unsafe { endpoint.UnregisterControlChangeNotify(&callback)? };
// avoid call drop and IUnknown::Release because the COM object was removed on device disconnection
// and call Release on a unexciting object can produce a deadlock
std::mem::forget(endpoint);
std::mem::forget(callback);
}
self.inputs.retain(|d| d.id != device_id);
self.outputs.retain(|d| d.id != device_id);
Expand Down

0 comments on commit addf232

Please sign in to comment.