Fix: Audio crash when trying to detect BGM_DISABLED #3150
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The introduction of #3080 exposed a bug where we were improperly detecting the
BGM_DISABLED
sequence.The bug previously was obscured if you didn't have any custom sequences loaded, as
BGM_DISABLED & 0xFF
is 255 and there was only like 110 sequences insequenceMap
meaning thatAudioLoad_GetFontsForSequence
would returnnull
. If you had custom sequences loaded, it was possible that the 255 would then load whatever font data exists for the sequence in that location (undefined behavior), but inAudio_PlayFanfare
the font data is never read, only that it is or isn't null, so nothing bad ever happened.With the voice additions from #3080, without custom sequences loaded,
sequenceMap
now has a size of 255, meaning that we were attempting to read the font data forBGM_DISABLED & 0xFF
which lead to a invalid pointer de-reference and crashing.When introducing custom sequences we removed one of the
& 0xFF
fromAudio_PlayFanfare
and added a check forBGM_DSIABLED
to prevent a audio crash. Although removing the other& 0xFF
from here will resolve the new audio crash in develop today, there is an incorrect sequence look up happening.In reviewing all uses of
Audio_PlayFanfare
there is no such fanfare ID aboveu8
even though sequence ID types areu16
, however sometimes the game will append0x900
to fanfare requests (Item Gets, opening big treasure chests, etc). This explains the original reason for& 0xFF
from the original game as the0x900
needs to be stripped off before looking up the sequence ID's font data.In this case, I have opted to bring back the original
& 0xFF
that we removed, and instead updated of catch forBGM_DISABLED
inAudioLoad_GetFontsForSequence
to account for seq ID being stripped tou8
range.I think this is the better approach to resolving the crashes and accounting for authentic behavior.
(I also synced some var names with decomp documentation while updating this)
Build Artifacts