cpal
cpal copied to clipboard
Panics on overflows with more than 1 channel
I created a cpal::StreamConfig for an output device for ALSA backend with following parameters:
channels: 2 (or more, if 5 it crashes even earlier),
sample_rate: 44100
buffer_size: Default
It panics with on multiply overflow:
thread '<unnamed>' panicked at 'attempt to multiply with overflow', /home/jduchniewicz/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.12.1/src/host/alsa/mod.rs:677:23
The offending lines are:
let buffer_size = stream.sample_format.sample_size() * available_samples;
or
let available_samples = avail_frames * stream.conf.channels as usize; when I even further increase the number of channels.
From my own investigation it looks like ALSA suddenly provides too many samples from PCM stream. First two transfers from cpal are fine, the third one is gigantic and overflows. Maybe this is not related to cpal, but to ALSA. However, I doubt it.
I had a similar issue:
thread '<unnamed>' panicked at 'attempt to multiply with overflow', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:692:23
On Arch Linux, the fix for me was to install pulseaudio-alsa:
sudo pacman -S pulseaudio-alsa
Also on Arch, pulseaudio-alsa was installed a long timke ago (and update), same issue:
thread '<unnamed>' panicked at 'attempt to multiply with overflow', /home/steven/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:692:23
I just added below as a work around
if avail_frames > 1024 * 1024 * 64 { return Ok(PollDescriptorsFlow::Continue); }
I just added below as a work around
if avail_frames > 1024 * 1024 * 64 { return Ok(PollDescriptorsFlow::Continue); }
Where did you put that?