diff --git a/CHANGES b/CHANGES index 132d5ae44..c73b2528b 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ Other fixes: - Core: Fix inconsistencies with setting game-specific overrides (fixes mgba.io/i/2963) - Debugger: Fix writing to specific segment in command-line debugger - GB: Fix uninitialized save data when loading undersized temporary saves + - GBA Audio: Fix crash if audio FIFOs and timers get out of sync - GBA Memory: Let raw access read high MMIO addresses - Qt: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560) - Qt: Fix potential crash when configuring shortcuts diff --git a/src/gba/audio.c b/src/gba/audio.c index aca2f2765..25e400b19 100644 --- a/src/gba/audio.c +++ b/src/gba/audio.c @@ -321,6 +321,9 @@ void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles) { int bits = 2 << GBARegisterSOUNDBIASGetResolution(audio->soundbias); until += 1 << (9 - GBARegisterSOUNDBIASGetResolution(audio->soundbias)); until >>= 9 - GBARegisterSOUNDBIASGetResolution(audio->soundbias); + if (UNLIKELY(bits < until)) { + until = bits; + } int i; for (i = bits - until; i < bits; ++i) { channel->samples[i] = channel->internalSample;