From 513071b60adee710486b31e74be38b0b0f761abc Mon Sep 17 00:00:00 2001 From: Artem Date: Sat, 14 Jul 2018 15:41:30 +0200 Subject: [PATCH] Don't panic when an audio device is disconnected. --- src/wasapi/stream.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/wasapi/stream.rs b/src/wasapi/stream.rs index 1b30c97..0f19157 100644 --- a/src/wasapi/stream.rs +++ b/src/wasapi/stream.rs @@ -494,6 +494,13 @@ impl EventLoop { let mut frames_available = { let mut padding = mem::uninitialized(); let hresult = (*stream.audio_client).GetCurrentPadding(&mut padding); + // Happens when a bluetooth headset was turned off, for example. + if hresult == AUDCLNT_E_DEVICE_INVALIDATED { + // The client code should switch to a different device eventually. + // For now let's just skip the invalidated device. + // Would be nice to inform the client code about the invalidation, + // but throwing a panic isn't the most ergonomic way to do so. + continue} check_result(hresult).unwrap(); stream.max_frames_in_buffer - padding };