Skip to content

Conversation

nahaharo
Copy link
Contributor

Fix for the MonoGame/MonoGame#8851

This code fixed two things in AudiroController.Update() at 2D game tutorial.

  1. move "_activeSoundEffectInstances.RemoveAt(index)" into if block.
  2. add index++ at the end of while statement.
    public void Update()
    {
        int index = 0;
        while (index < _activeSoundEffectInstances.Count)
        {
            SoundEffectInstance instance = _activeSoundEffectInstances[index];

            if (instance.State == SoundState.Stopped && !instance.IsDisposed)
            {
                instance.Dispose();
                _activeSoundEffectInstances.RemoveAt(index);
            }
            index++;
        }
    }

@nahaharo nahaharo changed the title Add index++ to 2D Tutorial's AudioController.Update() Minor fixes for the AudioController.Update() at 2D Tutorial Jun 20, 2025
@ThomasFOG
Copy link

I think it's still a bit broken, see MonoGame/docs.monogame.github.io#148 (comment)

@SimonDarksideJ
Copy link
Contributor

Can you review again @nahaharo / @AristurtleDev to ensure the update is the latest?

@nahaharo
Copy link
Contributor Author

I think its okay

@AristurtleDev
Copy link
Contributor

Sorry for the dealy on checking the changes.

@SimonDarksideJ The code looks good, it implements the reverse loop in each of the chapter sources.

Thanks for the contribution @nahaharo

@ThomasFOG ThomasFOG merged commit 1793359 into MonoGame:3.8.4 Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants