BUG in GameUtil.SoundManager
by Scott Goodwin · in Torque X 2D · 01/27/2008 (11:06 pm) · 1 replies
There are a couple of bugs in GameUtil.SoundManager. This is only a problem if you need to remove sound groups. Here's the gist of the problem (not too hard to fix).
1) in public virtual void Reset()
...
// unregister all sound groups
for (int i = 0; i < _soundGroups.Count; i++)
UnregisterSoundGroup(_soundGroups[i] as SoundGroup);
This doesn't work because _soundGroups is a HashTable so _soundGroups[i] as SoundGroup is always null.
If you fix this say by
foreach (DictionaryEntry myDE in _soundGroups)
UnregisterSoundGroup(myDE.Value as SoundGroup);
The next problem shows up
2) in public virtual void UnregisterSoundGroup(SoundGroup group)
...
_soundGroups.Remove(group);
This doesn't work because Remove expects a key, not a value.
If you fix this by passing in the key, then the Remove modifies the HashTable which will screw up the foreach in (1) above.
There are a few different ways to fix this depending on your preferences ...
1) in public virtual void Reset()
...
// unregister all sound groups
for (int i = 0; i < _soundGroups.Count; i++)
UnregisterSoundGroup(_soundGroups[i] as SoundGroup);
This doesn't work because _soundGroups is a HashTable so _soundGroups[i] as SoundGroup is always null.
If you fix this say by
foreach (DictionaryEntry myDE in _soundGroups)
UnregisterSoundGroup(myDE.Value as SoundGroup);
The next problem shows up
2) in public virtual void UnregisterSoundGroup(SoundGroup group)
...
_soundGroups.Remove(group);
This doesn't work because Remove expects a key, not a value.
If you fix this by passing in the key, then the Remove modifies the HashTable which will screw up the foreach in (1) above.
There are a few different ways to fix this depending on your preferences ...
About the author
Associate John Kanalakis
EnvyGames
John K.