Fix "bad_access error" when playing short time at high frequency with fade out #96
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.
I fixed a bug regarding the error: "EXC_BAD_ACCESS" which made the app crashed.
It occurs when playing sound short time at high frequency with fade out.
(at
ObjectAL/ObjectAL/Actions/OALActionManager.m#L160
)When starting fade out, a fade action added to
OALActionManager targetActions
, and it removed when fade out was completed. However, there is a time lag between releasingALSource
and removing fade action fromtargetActions
.App crashes during the time lag when a new
ALSource
is generated with the same id as the released oldAlSource
one and when an action from theALSource
is added to the to thetargetActions
.Regarding the
OALActionManager step:timer
, when a new fade action from theALSource
is attempting to be added, the id of the releasedALSource
however remains present in thetargets
. Therefore, the new fade action is added to the array of actions for oldALSource
intargetActions
. Next, the fade action of releasedALSource
is removed, but the id of releasedALSource
is not removed fromtargets
because the fade action of newALSource
remains in the array of actions intargetActions
. Hence the next timeOALActionManager step:timer
is called, the app will crash trying to reference the id of releasedALSource
intargets
.To fix it, I swapped the order of adding and removing actions in the code, and removed the master timer stop condition and placed it out, at the end of the adding/removing process.
The following code is for verification. It reproduces this bug.