MonoGame.Samples icon indicating copy to clipboard operation
MonoGame.Samples copied to clipboard

Minor fixes for the AudioController.Update() at 2D Tutorial

Open nahaharo opened this issue 6 months ago • 1 comments

Fix for the https://github.com/MonoGame/MonoGame/discussions/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 avatar Jun 20 '25 00:06 nahaharo

I think it's still a bit broken, see https://github.com/MonoGame/docs.monogame.github.io/pull/148#issuecomment-2990138927

ThomasFOG avatar Jun 20 '25 07:06 ThomasFOG

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

SimonDarksideJ avatar Jul 31 '25 17:07 SimonDarksideJ

I think its okay

nahaharo avatar Jul 31 '25 23:07 nahaharo

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

AristurtleDev avatar Aug 05 '25 18:08 AristurtleDev