From e292045572e59fd681cdbf9093bf9867f173690f Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Fri, 24 Nov 2017 19:35:49 -0600 Subject: [PATCH] Handle PulseAudio case where no data can be written. --- gtk/src/gtk_sound_driver_pulse.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gtk/src/gtk_sound_driver_pulse.cpp b/gtk/src/gtk_sound_driver_pulse.cpp index d5dca214..f7dd4b07 100644 --- a/gtk/src/gtk_sound_driver_pulse.cpp +++ b/gtk/src/gtk_sound_driver_pulse.cpp @@ -268,9 +268,23 @@ S9xPulseSoundDriver::samples_available (void) bytes = MIN (bytes, (samples << (Settings.SixteenBitSound ? 1 : 0))); + if (!bytes) + return; + lock (); - pa_stream_begin_write (stream, &output_buffer, &bytes); + if (pa_stream_begin_write (stream, &output_buffer, &bytes) != 0) + { + pa_stream_flush (stream, NULL, NULL); + unlock (); + return; + } + if (bytes <= 0 || !output_buffer) + { + unlock (); + return; + } + S9xMixSamples ((uint8 *) output_buffer, bytes >> (Settings.SixteenBitSound ? 1 : 0)); pa_stream_write (stream, output_buffer, bytes, NULL, 0, PA_SEEK_RELATIVE);