Skip to content

Commit 65e2f64

Browse files
nahaharoHyunwook Ha
andauthored
Fix for AudioController.Update() at 2d game tutorial. (#148)
* fix for AudioController.Update() at 2d game tutorial. * update code with backward iteration --------- Co-authored-by: Hyunwook Ha <hyunwookha@gmail.com>
1 parent e39f730 commit 65e2f64

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

articles/tutorials/building_2d_games/15_audio_controller/snippets/audiocontroller.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ public AudioController()
110110
/// </summary>
111111
public void Update()
112112
{
113-
int index = 0;
114-
115-
while (index < _activeSoundEffectInstances.Count)
113+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
116114
{
117-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
115+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
118116

119-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
117+
if (instance.State == SoundState.Stopped)
120118
{
121-
instance.Dispose();
119+
if (!instance.IsDisposed)
120+
{
121+
instance.Dispose();
122+
}
123+
_activeSoundEffectInstances.RemoveAt(i);
122124
}
123-
124-
_activeSoundEffectInstances.RemoveAt(index);
125125
}
126126
}
127127
#endregion

0 commit comments

Comments
 (0)