mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-13 07:57:51 +00:00
Fixed crash with very short music loop
https://forum.zdoom.org/viewtopic.php?t=59883
This commit is contained in:
parent
fae6f22a2b
commit
d58169f1b0
1 changed files with 10 additions and 5 deletions
|
@ -420,12 +420,17 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat
|
||||||
// This looks a bit more complicated than necessary because libmpg123 will not read the full requested length for the last block in the file.
|
// This looks a bit more complicated than necessary because libmpg123 will not read the full requested length for the last block in the file.
|
||||||
if (currentpos + framestoread > song->Loop_End)
|
if (currentpos + framestoread > song->Loop_End)
|
||||||
{
|
{
|
||||||
size_t endblock = (song->Loop_End - currentpos) * song->Channels * 2;
|
// Loop can be very short, make sure the current position doesn't exceed it
|
||||||
size_t endlen = song->Decoder->read(buff, endblock);
|
if (currentpos < song->Loop_End)
|
||||||
|
{
|
||||||
|
size_t endblock = (song->Loop_End - currentpos) * song->Channels * 2;
|
||||||
|
size_t endlen = song->Decoder->read(buff, endblock);
|
||||||
|
|
||||||
|
// Even if zero bytes was read give it a chance to start from the beginning
|
||||||
|
buff += endlen;
|
||||||
|
len -= endlen;
|
||||||
|
}
|
||||||
|
|
||||||
// Even if zero bytes was read give it a chance to start from the beginning
|
|
||||||
buff = buff + endlen;
|
|
||||||
len -= endlen;
|
|
||||||
song->Decoder->seek(song->Loop_Start, false, true);
|
song->Decoder->seek(song->Loop_Start, false, true);
|
||||||
}
|
}
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
|
|
Loading…
Reference in a new issue