SoundEffectInstance leaks #210

Closed
opened 2015-10-08 12:17:14 -04:00 by flibitijibibo · 1 comment
flibitijibibo commented 2015-10-08 12:17:14 -04:00 (Migrated from github.com)

In the current AudioManager, playing a sound is done by creating an instance before playing it:

https://github.com/SirCmpwn/TrueCraft/blob/master/TrueCraft.Client/AudioManager.cs#L117

The instance is not stored, however, so the native resources can get leaked and may result in lost sound after the resources have been fully expended.

The framework can manage these instances if SoundEffect.Play() is used...

https://msdn.microsoft.com/en-us/library/dd904205.aspx

... and that's basically the fix for the issue. The method becomes this:

        public void PlayPack(string pack, float volume = 1.0f)
        {
            var i = MathHelper.Random.Next(0, AudioPacks[pack].Length);
            AudioPacks[pack][i].Play(volume * EffectVolume, 1.0f, 0.0f);
        }

The downside to this is that looping and 3D positioning aren't supported, but TrueCraft does not currently use either feature. If either are needed, instance management will be needed as well.

In the current AudioManager, playing a sound is done by creating an instance before playing it: https://github.com/SirCmpwn/TrueCraft/blob/master/TrueCraft.Client/AudioManager.cs#L117 The instance is not stored, however, so the native resources can get leaked and may result in lost sound after the resources have been fully expended. The framework can manage these instances if SoundEffect.Play() is used... https://msdn.microsoft.com/en-us/library/dd904205.aspx ... and that's basically the fix for the issue. The method becomes this: ``` public void PlayPack(string pack, float volume = 1.0f) { var i = MathHelper.Random.Next(0, AudioPacks[pack].Length); AudioPacks[pack][i].Play(volume * EffectVolume, 1.0f, 0.0f); } ``` The downside to this is that looping and 3D positioning aren't supported, but TrueCraft does not currently use either feature. If either are needed, instance management will be needed as well.
ddevault commented 2015-10-08 13:17:25 -04:00 (Migrated from github.com)

Thanks for the head's up. Will address that.

Thanks for the head's up. Will address that.
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: AstralTransRocketries/TrueCraft#210
No description provided.