Fix for AudioController.Update() at 2d game tutorial.#148
Merged
SimonDarksideJ merged 3 commits intoMonoGame:mainfrom Jun 26, 2025
Merged
Fix for AudioController.Update() at 2d game tutorial.#148SimonDarksideJ merged 3 commits intoMonoGame:mainfrom
SimonDarksideJ merged 3 commits intoMonoGame:mainfrom
Conversation
AristurtleDev
approved these changes
Jun 20, 2025
Contributor
|
I think there is still an issue with this loop. If you remove an element from the list, you shouldn't increase the index, otherwise you would skip an element. Alternatively, you can iterate backward to simplify this and have a predictable loop: |
Contributor
Author
|
I think backward iteration is a better solution. public void Update()
{
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
{
SoundEffectInstance instance = _activeSoundEffectInstances[i];
if (instance.State == SoundState.Stopped)
{
if (!instance.IsDisposed)
{
instance.Dispose();
}
_activeSoundEffectInstances.RemoveAt(i);
}
}
} |
Collaborator
Yes, this version would be more preferable, please update @nahaharo |
nahaharo
pushed a commit
to nahaharo/MonoGame.Samples
that referenced
this pull request
Jun 25, 2025
SimonDarksideJ
approved these changes
Jun 26, 2025
Gaetz
pushed a commit
to Gaetz/docs.monogame.github.io
that referenced
this pull request
Jul 16, 2025
* fix for AudioController.Update() at 2d game tutorial. * update code with backward iteration --------- Co-authored-by: Hyunwook Ha <hyunwookha@gmail.com>
ThomasFOG
pushed a commit
to MonoGame/MonoGame.Samples
that referenced
this pull request
Aug 13, 2025
* Add index++ to 2D Tutorial's AudioController.Update() * Update Code according to MonoGame/docs.monogame.github.io#148 --------- Co-authored-by: Hyunwook Ha <hyunwookha@gmail.com> Co-authored-by: Simon (Darkside) Jackson <darkside@zenithmoon.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix for the MonoGame/MonoGame#8851
This code fixed two things in AudiroController.Update() at 2D game tutorial.