From c3b0a7fbbc678cfac7ac57a663319fb15f66fc0c Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 23 Feb 2025 14:14:23 +1000 Subject: [PATCH] Fix a bug in `ma_decoder_read_pcm_frames()`. This will abort reading early if the underlying data source returns an error. --- miniaudio.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/miniaudio.h b/miniaudio.h index 35348469..8e33d099 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -65747,6 +65747,14 @@ MA_API ma_result ma_decoder_read_pcm_frames(ma_decoder* pDecoder, void* pFramesO if (requiredInputFrameCount > 0) { result = ma_data_source_read_pcm_frames(pDecoder->pBackend, pIntermediaryBuffer, framesToReadThisIterationIn, &framesReadThisIterationIn); + + /* + Note here that even if we've reached the end, we don't want to abort because there might be more output frames needing to be + generated from cached input data, which might happen if resampling is being performed. + */ + if (result != MA_SUCCESS && result != MA_AT_END) { + break; + } } else { framesReadThisIterationIn = 0; pIntermediaryBuffer[0] = 0; /* <-- This is just to silence a static analysis warning. */