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)

This commit is contained in:
Regalis
2016-12-21 20:35:38 +02:00
parent c01ac33e1d
commit c3d29e41ad
4 changed files with 21 additions and 13 deletions

View File

@@ -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;

View File

@@ -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
}
}
}

View File

@@ -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();
}

View File

@@ -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)