mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 01:04:02 +02:00
Fix an infinite loop when reading from a data source with no data.
This commit is contained in:
+11
-1
@@ -43217,7 +43217,7 @@ static ma_result ma_data_source_resolve_current(ma_data_source* pDataSource, ma_
|
|||||||
pCurrentDataSource = (ma_data_source_base*)pDataSource; /* Not being used in a chain. Make sure we just always read from the data source itself at all times. */
|
pCurrentDataSource = (ma_data_source_base*)pDataSource; /* Not being used in a chain. Make sure we just always read from the data source itself at all times. */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pCurrentDataSource = pCurrentDataSource->pCurrent;
|
pCurrentDataSource = (ma_data_source_base*)pCurrentDataSource->pCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppCurrentDataSource = pCurrentDataSource;
|
*ppCurrentDataSource = pCurrentDataSource;
|
||||||
@@ -43279,6 +43279,7 @@ MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, voi
|
|||||||
ma_uint64 totalFramesProcessed = 0;
|
ma_uint64 totalFramesProcessed = 0;
|
||||||
ma_format format;
|
ma_format format;
|
||||||
ma_uint32 channels;
|
ma_uint32 channels;
|
||||||
|
ma_uint32 emptyLoopCounter = 0; /* Keeps track of how many times 0 frames have been read. For infinite loop detection of sounds with no audio data. */
|
||||||
|
|
||||||
if (pFramesRead != NULL) {
|
if (pFramesRead != NULL) {
|
||||||
*pFramesRead = 0;
|
*pFramesRead = 0;
|
||||||
@@ -43343,6 +43344,15 @@ MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, voi
|
|||||||
if so, switch to it.
|
if so, switch to it.
|
||||||
*/
|
*/
|
||||||
if (loop) {
|
if (loop) {
|
||||||
|
if (framesProcessed == 0) {
|
||||||
|
emptyLoopCounter += 1;
|
||||||
|
if (emptyLoopCounter > 1) {
|
||||||
|
break; /* Infinite loop detected. Get out. */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emptyLoopCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (ma_data_source_seek_to_pcm_frame(pCurrentDataSource, 0) != MA_SUCCESS) {
|
if (ma_data_source_seek_to_pcm_frame(pCurrentDataSource, 0) != MA_SUCCESS) {
|
||||||
break; /* Failed to loop. Abort. */
|
break; /* Failed to loop. Abort. */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user