From b063cf3febd63731d46a79e08418cb62f44b9d72 Mon Sep 17 00:00:00 2001 From: Regalis Date: Mon, 3 Apr 2017 20:59:02 +0300 Subject: [PATCH] Fire sound fix: the sounds were freed after each round without ever loading them again. The sound objects still existed and had some buffer ID assigned though, causing an incorrect clip to be played or OpenAL errors to be thrown on successive rounds. (Now freed sounds always have a buffer ID of -1) --- Subsurface/Source/Map/FireSource.cs | 17 ++++++----------- Subsurface/Source/Sounds/Sound.cs | 6 +++++- Subsurface/Source/Sounds/SoundManager.cs | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Subsurface/Source/Map/FireSource.cs b/Subsurface/Source/Map/FireSource.cs index 83c113986..d8d57e419 100644 --- a/Subsurface/Source/Map/FireSource.cs +++ b/Subsurface/Source/Map/FireSource.cs @@ -66,10 +66,10 @@ namespace Barotrauma hull = Hull.FindHull(worldPosition, spawningHull); if (hull == null || (!networkEvent && GameMain.Client!=null)) return; - if (fireSoundBasic==null) + if (fireSoundBasic == null) { - fireSoundBasic = Sound.Load("Content/Sounds/fire.ogg"); - fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg"); + fireSoundBasic = Sound.Load("Content/Sounds/fire.ogg", false); + fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg", false); } hull.AddFireSource(this, !networkEvent); @@ -78,13 +78,8 @@ namespace Barotrauma this.position = worldPosition - new Vector2(-5.0f, 5.0f) - Submarine.Position; - lightSource = new LightSource(this.position, 50.0f, new Color(1.0f, 0.9f, 0.7f), hull == null ? null : hull.Submarine); - - - - //this.position.Y = hull.Rect.Y - hull.Rect.Height; - + size = new Vector2(10.0f, 10.0f); } @@ -356,12 +351,12 @@ namespace Barotrauma lightSource.Remove(); - if (basicSoundIndex > -1) + if (basicSoundIndex > 0) { Sounds.SoundManager.Stop(basicSoundIndex); basicSoundIndex = -1; } - if (largeSoundIndex > -1) + if (largeSoundIndex > 0) { Sounds.SoundManager.Stop(largeSoundIndex); largeSoundIndex = -1; diff --git a/Subsurface/Source/Sounds/Sound.cs b/Subsurface/Source/Sounds/Sound.cs index 9ce6c8079..34714f97d 100644 --- a/Subsurface/Source/Sounds/Sound.cs +++ b/Subsurface/Source/Sounds/Sound.cs @@ -242,7 +242,11 @@ namespace Barotrauma SoundManager.ClearAlSource(AlBufferId); ALHelper.Check(); - if (oggSound != null) oggSound.Dispose(); + if (oggSound != null) + { + oggSound.Dispose(); + oggSound = null; + } } diff --git a/Subsurface/Source/Sounds/SoundManager.cs b/Subsurface/Source/Sounds/SoundManager.cs index e1184e983..4b1202da9 100644 --- a/Subsurface/Source/Sounds/SoundManager.cs +++ b/Subsurface/Source/Sounds/SoundManager.cs @@ -75,8 +75,8 @@ namespace Barotrauma.Sounds public static int Play(Sound sound, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f, bool loop=false) { - if (Disabled) return -1; - + if (Disabled || sound.AlBufferId == -1) return -1; + for (int i = 1; i < DefaultSourceCount; i++) { //find a source that's free to use (not playing or paused)