Fix for #2277: Failing to load sounds/music should never crash.
This commit is contained in:
committed by
Chris Forbes
parent
9201b1cced
commit
11da96fe22
@@ -29,6 +29,12 @@ namespace OpenRA
|
|||||||
|
|
||||||
static ISoundSource LoadSound(string filename)
|
static ISoundSource LoadSound(string filename)
|
||||||
{
|
{
|
||||||
|
if (!FileSystem.Exists(filename))
|
||||||
|
{
|
||||||
|
Log.Write("debug", "LoadSound, file does not exist: {0}", filename);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return LoadSoundRaw(AudLoader.LoadSound(FileSystem.Open(filename)));
|
return LoadSoundRaw(AudLoader.LoadSound(FileSystem.Open(filename)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,10 +146,12 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
StopMusic();
|
StopMusic();
|
||||||
|
|
||||||
|
var sound = sounds[m.Filename];
|
||||||
|
if (sound == null) return;
|
||||||
|
|
||||||
|
music = soundEngine.Play2D(sound, false, true, float2.Zero, MusicVolume);
|
||||||
currentMusic = m;
|
currentMusic = m;
|
||||||
MusicPlaying = true;
|
MusicPlaying = true;
|
||||||
var sound = sounds[m.Filename];
|
|
||||||
music = soundEngine.Play2D(sound, false, true, float2.Zero, MusicVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PlayMusic()
|
public static void PlayMusic()
|
||||||
@@ -357,6 +365,11 @@ namespace OpenRA
|
|||||||
|
|
||||||
public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume)
|
public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume)
|
||||||
{
|
{
|
||||||
|
if (sound == null)
|
||||||
|
{
|
||||||
|
Log.Write("debug", "Attempt to Play2D a null `ISoundSource`");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int source = GetSourceFromPool();
|
int source = GetSourceFromPool();
|
||||||
return new OpenAlSound(source, (sound as OpenAlSoundSource).buffer, loop, relative, pos, volume);
|
return new OpenAlSound(source, (sound as OpenAlSoundSource).buffer, loop, relative, pos, volume);
|
||||||
}
|
}
|
||||||
@@ -369,6 +382,8 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void PauseSound(ISound sound, bool paused)
|
public void PauseSound(ISound sound, bool paused)
|
||||||
{
|
{
|
||||||
|
if (sound == null) return;
|
||||||
|
|
||||||
int key = ((OpenAlSound)sound).source;
|
int key = ((OpenAlSound)sound).source;
|
||||||
int state;
|
int state;
|
||||||
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
|
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
|
||||||
@@ -410,6 +425,8 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void StopSound(ISound sound)
|
public void StopSound(ISound sound)
|
||||||
{
|
{
|
||||||
|
if (sound == null) return;
|
||||||
|
|
||||||
int key = ((OpenAlSound)sound).source;
|
int key = ((OpenAlSound)sound).source;
|
||||||
int state;
|
int state;
|
||||||
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
|
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
|
||||||
|
|||||||
Reference in New Issue
Block a user