While testing #183, I noticed that at least two GBC games cause Gambatte to generate a segfault (1942 and Alone in the Dark). This happens because the GB::runFor() function has an inaccurate description:
It accepts an audio buffer and a requested number of samples, claiming that up to (samples + 2064) samples will actually be generated
The audio buffer is therefore sized accordingly
In certain edge cases, GB::runFor() in fact generates an arbitrary number of samples - which overflow the supplied audio buffer and cause a segfault
This PR simply makes the audio handling code aware of the input buffer size, and 'clips' the generated output in the event that an overflow would occur. There are no longer any segfaults, and both 1942 and Alone in the Dark now run correctly.
While testing #183, I noticed that at least two GBC games cause Gambatte to generate a segfault (
1942
andAlone in the Dark
). This happens because theGB::runFor()
function has an inaccurate description:(samples + 2064)
samples will actually be generatedGB::runFor()
in fact generates an arbitrary number of samples - which overflow the supplied audio buffer and cause a segfaultThis PR simply makes the audio handling code aware of the input buffer size, and 'clips' the generated output in the event that an overflow would occur. There are no longer any segfaults, and both
1942
andAlone in the Dark
now run correctly.