From 3bc5b072779ba31026aa1080d044547006f63b29 Mon Sep 17 00:00:00 2001 From: evgeniysergeev Date: Mon, 31 Dec 2018 12:45:27 +0300 Subject: [PATCH] Fix for System.IO.InvalidDataException in VocLoader Fix for VOC version check use cached value from MoveNext instead of try/catch section --- OpenRA.Mods.Common/AudioLoaders/VocLoader.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/AudioLoaders/VocLoader.cs b/OpenRA.Mods.Common/AudioLoaders/VocLoader.cs index dcb969bd56..f75903029a 100644 --- a/OpenRA.Mods.Common/AudioLoaders/VocLoader.cs +++ b/OpenRA.Mods.Common/AudioLoaders/VocLoader.cs @@ -51,6 +51,7 @@ namespace OpenRA.Mods.Common.AudioLoaders readonly int totalSamples; IEnumerator currentBlock; + bool currentBlockEnded; int samplesLeftInBlock; int samplePosition; @@ -120,8 +121,8 @@ namespace OpenRA.Mods.Common.AudioLoaders throw new InvalidDataException("Voc header description not recognized"); if (vfh.DatablockOffset != 26) throw new InvalidDataException("Voc header offset is wrong"); - if (vfh.Version != 0x010A) - throw new InvalidDataException("Voc header version not recognized"); + if (vfh.Version < 0x0100 || vfh.Version >= 0x0200) + throw new InvalidDataException("Voc header version " + vfh.Version.ToString("X") + " not supported"); if (vfh.ID != ~vfh.Version + 0x1234) throw new InvalidDataException("Voc header id is bogus - expected: " + (~vfh.Version + 0x1234).ToString("X") + " but value is : " + vfh.ID.ToString("X")); @@ -271,7 +272,8 @@ namespace OpenRA.Mods.Common.AudioLoaders void Rewind() { - currentBlock = (IEnumerator)blocks.GetEnumerator(); + currentBlock = ((IEnumerable)blocks).GetEnumerator(); + currentBlockEnded = false; samplesLeftInBlock = 0; samplePosition = 0; @@ -284,9 +286,10 @@ namespace OpenRA.Mods.Common.AudioLoaders return; } } + currentBlockEnded = true; } - bool EndOfData { get { return currentBlock.Current.Equals(blocks.Last()) && samplesLeftInBlock == 0; } } + bool EndOfData { get { return currentBlockEnded && samplesLeftInBlock == 0; } } int FillBuffer(int maxSamples) { @@ -324,6 +327,7 @@ namespace OpenRA.Mods.Common.AudioLoaders samplesLeftInBlock = currentBlock.Current.SampleBlock.Samples; return; } + currentBlockEnded = true; } }