From e63db40bdfc00d2b568aa2deffeee5bb724e77ea Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Fri, 26 Apr 2024 23:23:04 -0400 Subject: [PATCH] Fix audio crash from null sfx (#15) --- ZAPD/ZAudio.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ZAPD/ZAudio.cpp b/ZAPD/ZAudio.cpp index 8c72cdd..f4e8c3d 100644 --- a/ZAPD/ZAudio.cpp +++ b/ZAPD/ZAudio.cpp @@ -109,9 +109,15 @@ SoundFontEntry* ZAudio::ParseSoundFontEntry(std::vector audioBank, int baseOffset) { SoundFontEntry* soundFont = new SoundFontEntry(); + + int sampleOffset = BitConverter::ToInt32BE(audioBank, soundFontOffset + 0) + baseOffset; + + if (sampleOffset == 0) + return nullptr; + soundFont->sampleEntry = ParseSampleEntry( audioBank, audioTable, audioSampleBankEntry, bankIndex, - BitConverter::ToInt32BE(audioBank, soundFontOffset + 0) + baseOffset, baseOffset); + sampleOffset, baseOffset); soundFont->tuning = BitConverter::ToFloatBE(audioBank, soundFontOffset + 4); return soundFont; @@ -258,7 +264,9 @@ void ZAudio::ParseSoundFont(std::vector codeData, std::vector SoundFontEntry* sfx; sfx = ParseSoundFontEntry(codeData, audioTable, audioSampleBank[sampleBankId1], sampleBankId1, currentOffset, ptr); - entry.soundEffects.push_back(sfx); + + //if (sfx != nullptr) + entry.soundEffects.push_back(sfx); currentOffset += 8; }