From c3d29e41adbb0021594d5e94d968083d70416ce0 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 21 Dec 2016 20:35:38 +0200 Subject: [PATCH] Additional null check in Wire Update, stopping paused sounds before deleting them (prevents an OpenAL error when switching to sub editor when the mainmenu drone sound is playing) --- Subsurface/Source/Items/Components/Signal/Wire.cs | 2 +- Subsurface/Source/Sounds/OggStream.cs | 11 ++++++----- Subsurface/Source/Sounds/Sound.cs | 9 +++++---- Subsurface/Source/Sounds/SoundManager.cs | 12 +++++++++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index 25bc4664a..370527b3c 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -239,7 +239,7 @@ namespace Barotrauma.Items.Components if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine; if (connections[1] != null && connections[1].Item.Submarine != null) sub = connections[1].Item.Submarine; - if (item.Submarine != sub && Screen.Selected != GameMain.EditMapScreen) + if ((item.Submarine != sub || sub == null) && Screen.Selected != GameMain.EditMapScreen) { ClearConnections(); return; diff --git a/Subsurface/Source/Sounds/OggStream.cs b/Subsurface/Source/Sounds/OggStream.cs index d2c9a5a7a..d877cc14f 100644 --- a/Subsurface/Source/Sounds/OggStream.cs +++ b/Subsurface/Source/Sounds/OggStream.cs @@ -47,14 +47,15 @@ namespace Barotrauma.Sounds public static void Check() { -#if !DEBUG - return; -#endif - ALError error; if ((error = AL.GetError()) != ALError.NoError) { - DebugConsole.ThrowError("OpenAL error: "+AL.GetErrorString(error)); +#if DEBUG + DebugConsole.ThrowError("OpenAL error: " + AL.GetErrorString(error)); +#else + + DebugConsole.NewMessage("OpenAL error: "+AL.GetErrorString(error), Microsoft.Xna.Framework.Color.Red); +#endif } } } diff --git a/Subsurface/Source/Sounds/Sound.cs b/Subsurface/Source/Sounds/Sound.cs index 5cfb62e89..867ae39f4 100644 --- a/Subsurface/Source/Sounds/Sound.cs +++ b/Subsurface/Source/Sounds/Sound.cs @@ -247,7 +247,8 @@ namespace Barotrauma loadedSounds.Remove(this); - if (alSourceId>0 && SoundManager.IsPlaying(alSourceId)) + if (alSourceId > 0 && + (SoundManager.IsPlaying(alSourceId) || SoundManager.IsPaused(alSourceId))) { SoundManager.Stop(alSourceId); ALHelper.Check(); @@ -258,10 +259,10 @@ namespace Barotrauma if (s.oggSound == oggSound) return; } - //System.Diagnostics.Debug.WriteLine("Removing sound " + filePath + " (buffer id" + AlBufferId + ")"); - SoundManager.ClearAlSource(AlBufferId); - if (oggSound!=null) oggSound.Dispose(); + ALHelper.Check(); + + if (oggSound != null) oggSound.Dispose(); } diff --git a/Subsurface/Source/Sounds/SoundManager.cs b/Subsurface/Source/Sounds/SoundManager.cs index 3c28bc280..86607bc00 100644 --- a/Subsurface/Source/Sounds/SoundManager.cs +++ b/Subsurface/Source/Sounds/SoundManager.cs @@ -149,12 +149,18 @@ namespace Barotrauma.Sounds return soundsPlaying[sourceIndex]; } - public static bool IsPlaying(int sourceIndex) { if (sourceIndex < 1 || sourceIndex>alSources.Count-1) return false; - var state = AL.GetSourceState(alSources[sourceIndex]); - return (state == ALSourceState.Playing); + + return AL.GetSourceState(alSources[sourceIndex]) == ALSourceState.Playing; + } + + public static bool IsPaused(int sourceIndex) + { + if (sourceIndex < 1 || sourceIndex > alSources.Count - 1) return false; + + return AL.GetSourceState(alSources[sourceIndex]) == ALSourceState.Paused; } public static bool IsLooping(int sourceIndex)