Skip to content

Commit

Permalink
Fix audio crash from null sfx (HarbourMasters#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
NEstelami authored Apr 27, 2024
1 parent 870387e commit e63db40
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ZAPD/ZAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e63db40

Please sign in to comment.