Reset stream position after TryParseSound failures

This commit is contained in:
Matthias Mailänder
2016-01-13 15:03:27 +01:00
parent d578ea4094
commit 047f71e5ec
4 changed files with 16 additions and 3 deletions

View File

@@ -170,6 +170,7 @@ namespace OpenRA.FileFormats
out int sampleRate) out int sampleRate)
{ {
channels = sampleBits = sampleRate = 0; channels = sampleBits = sampleRate = 0;
var position = stream.Position;
try try
{ {
@@ -187,6 +188,10 @@ namespace OpenRA.FileFormats
rawData = null; rawData = null;
return false; return false;
} }
finally
{
stream.Position = position;
}
channels = 1; channels = 1;
sampleBits = 16; sampleBits = 16;

View File

@@ -19,6 +19,8 @@ namespace OpenRA.FileFormats
{ {
bool ISoundLoader.TryParseSound(Stream stream, string fileName, out byte[] rawData, out int channels, out int sampleBits, out int sampleRate) bool ISoundLoader.TryParseSound(Stream stream, string fileName, out byte[] rawData, out int channels, out int sampleBits, out int sampleRate)
{ {
var position = stream.Position;
try try
{ {
var vocStream = new VocStream(stream); var vocStream = new VocStream(stream);
@@ -33,6 +35,10 @@ namespace OpenRA.FileFormats
channels = sampleBits = sampleRate = 0; channels = sampleBits = sampleRate = 0;
return false; return false;
} }
finally
{
stream.Position = position;
}
return true; return true;
} }

View File

@@ -181,6 +181,7 @@ namespace OpenRA.FileFormats
{ {
rawData = null; rawData = null;
channels = sampleBits = sampleRate = 0; channels = sampleBits = sampleRate = 0;
var position = stream.Position;
try try
{ {
@@ -197,6 +198,10 @@ namespace OpenRA.FileFormats
Log.Write("sound", e.ToString()); Log.Write("sound", e.ToString());
return false; return false;
} }
finally
{
stream.Position = position;
}
rawData = RawOutput; rawData = RawOutput;
channels = Channels; channels = Channels;

View File

@@ -63,11 +63,8 @@ namespace OpenRA
int sampleBits; int sampleBits;
int sampleRate; int sampleRate;
foreach (var loader in Game.ModData.SoundLoaders) foreach (var loader in Game.ModData.SoundLoaders)
{
stream.Position = 0;
if (loader.TryParseSound(stream, filename, out rawData, out channels, out sampleBits, out sampleRate)) if (loader.TryParseSound(stream, filename, out rawData, out channels, out sampleBits, out sampleRate))
return soundEngine.AddSoundSourceFromMemory(rawData, channels, sampleBits, sampleRate); return soundEngine.AddSoundSourceFromMemory(rawData, channels, sampleBits, sampleRate);
}
throw new InvalidDataException(filename + " is not a valid sound file!"); throw new InvalidDataException(filename + " is not a valid sound file!");
} }