summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Estelami <NEstelami@users.noreply.github.com>2024-04-26 23:23:04 -0400
committerGitHub <noreply@github.com>2024-04-26 23:23:04 -0400
commite63db40bdfc00d2b568aa2deffeee5bb724e77ea (patch)
treef65fe64580b76f8ae3b209397254fcd984b688e1
parent870387e9d2ded57913b9dbc87214c05f1e1e7a04 (diff)
Fix audio crash from null sfx (#15)
-rw-r--r--ZAPD/ZAudio.cpp12
1 files 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<uint8_t> 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<uint8_t> codeData, std::vector<uint8_t>
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;
}