From 54fe965bc019ebc6e96a0c04a0a5550c1ca8b2fe Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 1 Aug 2020 11:39:58 +1000 Subject: [PATCH] Fix some bugs in ma_data_source_read_pcm_frames() * A crash when the pFramesRead parameter is null * Looping not working due to MA_AT_END now being returned. Public issue https://github.com/dr-soft/miniaudio/issues/185 --- miniaudio.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 370e7dd1..f8273649 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -41230,7 +41230,7 @@ MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, voi If we encounted an error from the read callback, make sure it's propagated to the caller. The caller may need to know whether or not MA_BUSY is returned which is not necessarily considered an error. */ - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS && result != MA_AT_END) { break; } @@ -41238,7 +41238,7 @@ MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, voi We can determine if we've reached the end by checking the return value of the onRead() callback. If it's less than what we requested it means we've reached the end. To loop back to the start, all we need to do is seek back to the first frame. */ - if (framesProcessed < framesRemaining) { + if (framesProcessed < framesRemaining || result == MA_AT_END) { if (ma_data_source_seek_to_pcm_frame(pDataSource, 0) != MA_SUCCESS) { break; } @@ -41249,7 +41249,10 @@ MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, voi } } - *pFramesRead = totalFramesProcessed; + if (pFramesRead != NULL) { + *pFramesRead = totalFramesProcessed; + } + return result; } } @@ -62309,6 +62312,8 @@ v0.10.16 - TBD - OpenSL: Enable runtime linking. - OpenSL: Fix a multithreading bug when initializing and uninitializing multiple contexts at the same time. - iOS: Improvements to device enumeration. + - Fix a crash in ma_data_source_read_pcm_frames() when the output frame count parameter is NULL. + - Fix a bug in ma_data_source_read_pcm_frames() where looping doesn't work. - Fix some compilation warnings on Windows when both DirectSound and WinMM are disabled. - Fix some compilation warnings when no decoders are enabled. - Updates to documentation.