From 047f71e5eceba3153d5b030639f340578fa8cef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 13 Jan 2016 15:03:27 +0100 Subject: [PATCH] Reset stream position after TryParseSound failures --- OpenRA.Game/FileFormats/AudLoader.cs | 5 +++++ OpenRA.Game/FileFormats/VocLoader.cs | 6 ++++++ OpenRA.Game/FileFormats/WavLoader.cs | 5 +++++ OpenRA.Game/Sound/Sound.cs | 3 --- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/FileFormats/AudLoader.cs b/OpenRA.Game/FileFormats/AudLoader.cs index 2860fa93ef..311b2a165f 100644 --- a/OpenRA.Game/FileFormats/AudLoader.cs +++ b/OpenRA.Game/FileFormats/AudLoader.cs @@ -170,6 +170,7 @@ namespace OpenRA.FileFormats out int sampleRate) { channels = sampleBits = sampleRate = 0; + var position = stream.Position; try { @@ -187,6 +188,10 @@ namespace OpenRA.FileFormats rawData = null; return false; } + finally + { + stream.Position = position; + } channels = 1; sampleBits = 16; diff --git a/OpenRA.Game/FileFormats/VocLoader.cs b/OpenRA.Game/FileFormats/VocLoader.cs index a7c19f6235..2810dff310 100644 --- a/OpenRA.Game/FileFormats/VocLoader.cs +++ b/OpenRA.Game/FileFormats/VocLoader.cs @@ -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) { + var position = stream.Position; + try { var vocStream = new VocStream(stream); @@ -33,6 +35,10 @@ namespace OpenRA.FileFormats channels = sampleBits = sampleRate = 0; return false; } + finally + { + stream.Position = position; + } return true; } diff --git a/OpenRA.Game/FileFormats/WavLoader.cs b/OpenRA.Game/FileFormats/WavLoader.cs index a6b0da6ada..c9e740c3ff 100644 --- a/OpenRA.Game/FileFormats/WavLoader.cs +++ b/OpenRA.Game/FileFormats/WavLoader.cs @@ -181,6 +181,7 @@ namespace OpenRA.FileFormats { rawData = null; channels = sampleBits = sampleRate = 0; + var position = stream.Position; try { @@ -197,6 +198,10 @@ namespace OpenRA.FileFormats Log.Write("sound", e.ToString()); return false; } + finally + { + stream.Position = position; + } rawData = RawOutput; channels = Channels; diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index c78e03b00b..2904219415 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -63,11 +63,8 @@ namespace OpenRA int sampleBits; int sampleRate; foreach (var loader in Game.ModData.SoundLoaders) - { - stream.Position = 0; if (loader.TryParseSound(stream, filename, out rawData, out channels, out sampleBits, out sampleRate)) return soundEngine.AddSoundSourceFromMemory(rawData, channels, sampleBits, sampleRate); - } throw new InvalidDataException(filename + " is not a valid sound file!"); }