From f51589c55261550407dc12dedd7a3e5512be77e1 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 31 Aug 2023 16:57:39 -0700 Subject: [PATCH] Replace assert in WASAPI check with bubble'd error (#797) Replace assert in WASAPI WAVEFORMTEX supported format check with bubbled error message. For our use case, this stops a crash that pops up for some users who encounter this path and allows us to gracefully just not play audio and log a message elsewhere. --- src/host/wasapi/device.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index 2bf9224..6f641c9 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -441,7 +441,12 @@ impl Device { .map_err(windows_err_to_cpal_err::)?; // If the default format can't succeed we have no hope of finding other formats. - assert!(is_format_supported(client, default_waveformatex_ptr.0)?); + if !is_format_supported(client, default_waveformatex_ptr.0)? { + let description = + "Could not determine support for default `WAVEFORMATEX`".to_string(); + let err = BackendSpecificError { description }; + return Err(err.into()); + } // Copy the format to use as a test format (as to avoid mutating the original format). let mut test_format = {