Add RemoveComponents example to demo 'infinite' system bug #23
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.
Description
When you use
AudioFileEndBehavior::RemoveComponents
, the system that actually handles the removal of the components loops infinitely. To repro, run the example and look in the terminal at the 'infinite' log entry.The removal code removes
AudioFileBundle
but the query that the system uses queries forAudioHandle<AudioFileHandle>
, and that's not a part ofAudioFileBundle
therefore the query always matches.I think the logic error is that the removal code assumes that removing
AudioFileBundle
is enough, because that's the minimal set of components callers need to add to an entity to make it play audio audio. However, bevy-kira-components can internally add more components. In this case it addsAudioHandle
:bevy-kira-components/src/sources/mod.rs
Line 170 in d9bd5ab
Therefore I think one solution is that the removal code just needs to be aware of all of the extra components it may add and one fix looks like this:
This seems to be in line with the original goal of
RemoveComponents
which is to make the entity look how it looked before the caller addedAudioFileBundle
i.e. the caller is really asking bevy-kira-components "please: remove all the audio components".P.S. It was easier to just push the repro example as a PR than create a new issue and I also thought that if it was desired we could keep this example, and once the bug is fixed we can enable the
on_audio_file_removed
to demonstrate how you can change sounds once the previous sound has finished playing.