fix SDL2 audio thread hanging on close

This commit is contained in:
lifning 2021-08-17 16:50:26 -07:00
parent 12b879ac9f
commit d156c04a04
3 changed files with 3 additions and 5 deletions

View File

@ -392,7 +392,7 @@ impl AudioCallback for MySdlAudio {
fn callback(&mut self, out: &mut [Self::Channel]) {
if self.audio_spec.format == AudioFormat::S16LSB {
if let Ok(samples) = self.audio_receiver.recv() {
if let Ok(samples) = self.audio_receiver.recv_timeout(Duration::from_millis(500)) {
out.copy_from_slice(&samples[..out.len()]);
}
}

View File

@ -10,9 +10,7 @@ use std::io::Read;
pub struct RetroComponentBase {
retro: LibretroWrapper,
libretro_path: PathBuf,
// TODO: control when things get added to this.
// probably shouldn't be after load_game?
// unless we invent a way to play back the latest set_pixel_format etc. metadata required.
// TODO: control when things get added to this with lifetime constraints defined by implementers
components: Vec<Box<dyn RetroComponent>>,
// replaying env calls for late-added components

View File

@ -284,7 +284,7 @@ impl AudioCallback for MySdlAudio {
fn callback(&mut self, out: &mut [Self::Channel]) {
if self.audio_spec.format == AudioFormat::S16LSB {
if let Ok(samples) = self.audio_receiver.recv() {
if let Ok(samples) = self.audio_receiver.recv_timeout(Duration::from_millis(500)) {
out.copy_from_slice(&samples[..out.len()]);
}
}