Added some extra information to OpenAL error messages
This commit is contained in:
@@ -56,7 +56,7 @@ namespace Barotrauma.Sounds
|
||||
AL.BufferData(sound.alBufferId, reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, sound.castBuffer,
|
||||
readSamples * sizeof(short), reader.SampleRate);
|
||||
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(oggFile);
|
||||
}
|
||||
|
||||
//AL.Source(alSourceId, ALSourcei.Buffer, alBufferId);
|
||||
@@ -100,12 +100,12 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//var state = AL.GetSourceState(alSourceId);
|
||||
//if (state == ALSourceState.Playing || state == ALSourceState.Paused)
|
||||
// Stop();
|
||||
System.Diagnostics.Debug.WriteLine(alBufferId);
|
||||
//AL.DeleteSource(alSourceId);
|
||||
AL.DeleteBuffer(alBufferId);
|
||||
if (alBufferId > 0)
|
||||
{
|
||||
AL.DeleteBuffer(alBufferId);
|
||||
alBufferId = 0;
|
||||
}
|
||||
|
||||
//if (ALHelper.Efx.IsInitialized)
|
||||
// ALHelper.Efx.DeleteFilter(alFilterId);
|
||||
|
||||
@@ -45,20 +45,24 @@ namespace Barotrauma.Sounds
|
||||
//logHandler(String.Format("Total memory : {0:0.###} {1} ", usedHeap, sizes[order]), 0, 6);
|
||||
}
|
||||
|
||||
public static void Check()
|
||||
public static void Check(string extraErrorMsg = "")
|
||||
{
|
||||
ALError error;
|
||||
if ((error = AL.GetError()) != ALError.NoError)
|
||||
{
|
||||
string errorMsg = "OpenAL error: " + AL.GetErrorString(error);
|
||||
if (!string.IsNullOrEmpty(extraErrorMsg)) errorMsg += " {" + extraErrorMsg + "} ";
|
||||
errorMsg += "\n" + Environment.StackTrace;
|
||||
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("OpenAL error: " + AL.GetErrorString(error) + "\n" + Environment.StackTrace);
|
||||
DebugConsole.ThrowError(errorMsg);
|
||||
#else
|
||||
DebugConsole.NewMessage("OpenAL error: " + AL.GetErrorString(error) + "\n" + Environment.StackTrace, Microsoft.Xna.Framework.Color.Red);
|
||||
DebugConsole.NewMessage(errorMsg, Microsoft.Xna.Framework.Color.Red);
|
||||
#endif
|
||||
GameAnalyticsManager.AddErrorEventOnce(
|
||||
"OggStream.Check:"+ AL.GetErrorString(error),
|
||||
"OggStream.Check:" + AL.GetErrorString(error) + extraErrorMsg,
|
||||
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||
"OpenAL error: " + AL.GetErrorString(error) + "\n" + Environment.StackTrace);
|
||||
errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,9 +91,17 @@ namespace Barotrauma.Sounds
|
||||
public Action<string, int, int> LogHandler;
|
||||
#endif
|
||||
|
||||
public OggStream(string filename, int bufferCount = DefaultBufferCount) : this(File.OpenRead(filename), bufferCount) { }
|
||||
public OggStream(Stream stream, int bufferCount = DefaultBufferCount)
|
||||
public string FileName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public OggStream(string filename, int bufferCount = DefaultBufferCount) : this(File.OpenRead(filename), filename, bufferCount) { }
|
||||
public OggStream(Stream stream, string fileName, int bufferCount = DefaultBufferCount)
|
||||
{
|
||||
this.FileName = fileName;
|
||||
|
||||
BufferCount = bufferCount;
|
||||
|
||||
alBufferIds = AL.GenBuffers(bufferCount);
|
||||
@@ -98,7 +110,7 @@ namespace Barotrauma.Sounds
|
||||
if (ALHelper.XRam.IsInitialized)
|
||||
{
|
||||
ALHelper.XRam.SetBufferMode(BufferCount, ref alBufferIds[0], XRamExtension.XRamStorage.Hardware);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(fileName);
|
||||
}
|
||||
|
||||
if (ALHelper.Efx.IsInitialized)
|
||||
@@ -167,7 +179,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
AL.SourcePlay(alSourceId);
|
||||
this.Volume = volume;
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
|
||||
Preparing = false;
|
||||
|
||||
@@ -181,7 +193,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
OggStreamer.Instance.RemoveStream(this);
|
||||
AL.SourcePause(alSourceId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
@@ -191,7 +203,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
OggStreamer.Instance.AddStream(this);
|
||||
AL.SourcePlay(alSourceId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -230,7 +242,7 @@ namespace Barotrauma.Sounds
|
||||
set
|
||||
{
|
||||
AL.Source(alSourceId, ALSourcef.Gain, volume = value);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,20 +272,20 @@ namespace Barotrauma.Sounds
|
||||
/*if (ALHelper.Efx.IsInitialized)
|
||||
ALHelper.Efx.DeleteFilter(alFilterId);*/
|
||||
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
}
|
||||
|
||||
void StopPlayback()
|
||||
{
|
||||
AL.SourceStop(alSourceId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
}
|
||||
|
||||
void Empty()
|
||||
{
|
||||
int queued;
|
||||
AL.GetSource(alSourceId, ALGetSourcei.BuffersQueued, out queued);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
|
||||
if (queued > 0)
|
||||
{
|
||||
@@ -296,12 +308,12 @@ namespace Barotrauma.Sounds
|
||||
if (processed > 0)
|
||||
{
|
||||
AL.SourceUnqueueBuffers(alSourceId, processed, salvaged);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
}
|
||||
|
||||
// Try turning it off again?
|
||||
AL.SourceStop(alSourceId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
|
||||
Empty();
|
||||
}
|
||||
@@ -318,7 +330,7 @@ namespace Barotrauma.Sounds
|
||||
// Fill first buffer synchronously
|
||||
OggStreamer.Instance.FillBuffer(this, alBufferIds[0]);
|
||||
AL.SourceQueueBuffer(alSourceId, alBufferIds[0]);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(FileName);
|
||||
|
||||
// Schedule the others asynchronously
|
||||
OggStreamer.Instance.AddStream(this);
|
||||
@@ -433,7 +445,7 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, castBuffer,
|
||||
readSamples * sizeof(short), stream.Reader.SampleRate);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(stream.FileName);
|
||||
|
||||
return readSamples != BufferSize;
|
||||
}
|
||||
@@ -470,10 +482,10 @@ namespace Barotrauma.Sounds
|
||||
|
||||
int queued;
|
||||
AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersQueued, out queued);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(stream.FileName);
|
||||
int processed;
|
||||
AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersProcessed, out processed);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(stream.FileName);
|
||||
|
||||
if (processed == 0 && queued == stream.BufferCount) continue;
|
||||
|
||||
@@ -500,7 +512,7 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
|
||||
AL.SourceQueueBuffers(stream.alSourceId, tempBuffers.Length, tempBuffers);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(stream.FileName);
|
||||
|
||||
if (finished && !stream.IsLooped)
|
||||
continue;
|
||||
@@ -518,7 +530,7 @@ namespace Barotrauma.Sounds
|
||||
if (state == ALSourceState.Stopped)
|
||||
{
|
||||
AL.SourcePlay(stream.alSourceId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(stream.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Barotrauma
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to load sound "+file+"!", e);
|
||||
}
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(file);
|
||||
}
|
||||
|
||||
baseVolume = 1.0f;
|
||||
@@ -219,7 +219,7 @@ namespace Barotrauma
|
||||
(SoundManager.IsPlaying(alSourceId) || SoundManager.IsPaused(alSourceId)))
|
||||
{
|
||||
SoundManager.Stop(alSourceId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(filePath);
|
||||
}
|
||||
|
||||
foreach (Sound s in loadedSounds)
|
||||
@@ -228,7 +228,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
SoundManager.ClearAlSource(AlBufferId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(filePath);
|
||||
|
||||
if (oggSound != null)
|
||||
{
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Barotrauma.Sounds
|
||||
volume = 0.0f;
|
||||
}
|
||||
|
||||
if (sourceIndex<1 || soundsPlaying[sourceIndex] != sound)
|
||||
if (sourceIndex < 1 || soundsPlaying[sourceIndex] != sound)
|
||||
{
|
||||
sourceIndex = Play(sound, position, volume, 0.0f, true);
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace Barotrauma.Sounds
|
||||
AL.Source(alSources[sourceIndex], ALSourceb.Looping, true);
|
||||
}
|
||||
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(sound?.FilePath);
|
||||
return sourceIndex;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace Barotrauma.Sounds
|
||||
return;
|
||||
|
||||
AL.SourcePause(alSources[sourceIndex]);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(soundsPlaying[sourceIndex]?.FilePath);
|
||||
}
|
||||
|
||||
public static void Resume(int sourceIndex)
|
||||
@@ -176,7 +176,7 @@ namespace Barotrauma.Sounds
|
||||
return;
|
||||
|
||||
AL.SourcePlay(alSources[sourceIndex]);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(soundsPlaying[sourceIndex]?.FilePath);
|
||||
}
|
||||
|
||||
public static void Stop(int sourceIndex)
|
||||
@@ -291,7 +291,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = value);
|
||||
ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(soundsPlaying[i]?.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -316,7 +316,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassGain);
|
||||
ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId);
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(soundsPlaying[sourceIndex]?.FilePath);
|
||||
}
|
||||
|
||||
public static OggStream StartStream(string file, float volume = 1.0f)
|
||||
@@ -331,7 +331,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
oggStream.Play(volume);
|
||||
|
||||
ALHelper.Check();
|
||||
ALHelper.Check(file);
|
||||
|
||||
return oggStream;
|
||||
}
|
||||
@@ -361,15 +361,15 @@ namespace Barotrauma.Sounds
|
||||
|
||||
for (int i = 0; i < DefaultSourceCount; i++)
|
||||
{
|
||||
string soundPath = soundsPlaying[i]?.FilePath;
|
||||
var state = OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]);
|
||||
if (state == OpenTK.Audio.OpenAL.ALSourceState.Playing || state == OpenTK.Audio.OpenAL.ALSourceState.Paused)
|
||||
{
|
||||
Stop(i);
|
||||
}
|
||||
|
||||
OpenTK.Audio.OpenAL.AL.DeleteSource(alSources[i]);
|
||||
|
||||
ALHelper.Check();
|
||||
OpenTK.Audio.OpenAL.AL.DeleteSource(alSources[i]);
|
||||
ALHelper.Check(soundPath);
|
||||
}
|
||||
|
||||
if (oggStream != null)
|
||||
|
||||
Reference in New Issue
Block a user