Skip to content

Fix another infinite loop in mix_source_buffer(), case of uneven input#40

Merged
icculus merged 1 commit into
icculus:sdl2from
ivan-mogilko:fix--mixerinfiniteloop2
Apr 27, 2026
Merged

Fix another infinite loop in mix_source_buffer(), case of uneven input#40
icculus merged 1 commit into
icculus:sdl2from
ivan-mogilko:fix--mixerinfiniteloop2

Conversation

@ivan-mogilko
Copy link
Copy Markdown
Contributor

@ivan-mogilko ivan-mogilko commented Apr 27, 2026

This fixes another potential infinite loop (first one was fixed by #31), which may occur if remaining data in the input is less than bufferframesize. There are seemingly two options here:

  1. Skip the remainder.
  2. Use a local temp buffer, copy the remainder over and fill necessary remaining bytes with zeroes, then pass it into mix_buffer() too.

I chose the first, as this ever affects only 1 last sample which, apparently, does not have all of the channels data filled, so this does not seem to be worth it.

On a separate note, I suspect that instead of these workarounds, mojoAL could fix the buffer length in alBufferData, clamping it to the multiple of framesize. But I dont know the program too well, so idk if adjusting buffer's "length" value in this case may lead to any bad consequences.

This fixes another potential infinite loop, which may occur if remaining data in the input is less than `bufferframesize`, in such case `framesavail` resulted in 0, and src->offset never advanced.
There are seemingly two options here:
1. Skip the remainder.
2. Use a local temp buffer, copy the remainder over and fill necessary remaining bytes with zeroes, then pass it into mix_buffer() too.

I chose the first, as this ever affects only 1 last sample which, apparently, does not have all of the channels data filled, so this does not seem to be worth it.
@icculus icculus merged commit 234ec03 into icculus:sdl2 Apr 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants