Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak when playing videos #14510

Merged
merged 1 commit into from Dec 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions OpenRA.Game/Sound/Sound.cs
Expand Up @@ -40,7 +40,7 @@ public sealed class Sound : IDisposable
ISoundLoader[] loaders;
IReadOnlyFileSystem fileSystem;
Cache<string, ISoundSource> sounds;
ISoundSource rawSource;
ISoundSource videoSource;
ISound music;
ISound video;
MusicInfo currentMusic;
Expand Down Expand Up @@ -149,8 +149,9 @@ public void UnmuteAudio()

public void PlayVideo(byte[] raw, int channels, int sampleBits, int sampleRate)
{
rawSource = soundEngine.AddSoundSourceFromMemory(raw, channels, sampleBits, sampleRate);
video = soundEngine.Play2D(rawSource, false, true, WPos.Zero, InternalSoundVolume, false);
StopVideo();
videoSource = soundEngine.AddSoundSourceFromMemory(raw, channels, sampleBits, sampleRate);
video = soundEngine.Play2D(videoSource, false, true, WPos.Zero, InternalSoundVolume, false);
}

public void PlayVideo()
Expand All @@ -168,7 +169,12 @@ public void PauseVideo()
public void StopVideo()
{
if (video != null)
{
soundEngine.StopSound(video);
videoSource.Dispose();
videoSource = null;
video = null;
}
}

public void Tick()
Expand Down