Fix for System.IO.InvalidDataException in VocLoader

Fix for VOC version check

use cached value from MoveNext instead of try/catch section
This commit is contained in:
evgeniysergeev
2018-12-31 12:45:27 +03:00
committed by reaperrr
parent 72dbb871ac
commit 3bc5b07277

View File

@@ -51,6 +51,7 @@ namespace OpenRA.Mods.Common.AudioLoaders
readonly int totalSamples; readonly int totalSamples;
IEnumerator<VocBlock> currentBlock; IEnumerator<VocBlock> currentBlock;
bool currentBlockEnded;
int samplesLeftInBlock; int samplesLeftInBlock;
int samplePosition; int samplePosition;
@@ -120,8 +121,8 @@ namespace OpenRA.Mods.Common.AudioLoaders
throw new InvalidDataException("Voc header description not recognized"); throw new InvalidDataException("Voc header description not recognized");
if (vfh.DatablockOffset != 26) if (vfh.DatablockOffset != 26)
throw new InvalidDataException("Voc header offset is wrong"); throw new InvalidDataException("Voc header offset is wrong");
if (vfh.Version != 0x010A) if (vfh.Version < 0x0100 || vfh.Version >= 0x0200)
throw new InvalidDataException("Voc header version not recognized"); throw new InvalidDataException("Voc header version " + vfh.Version.ToString("X") + " not supported");
if (vfh.ID != ~vfh.Version + 0x1234) if (vfh.ID != ~vfh.Version + 0x1234)
throw new InvalidDataException("Voc header id is bogus - expected: " + throw new InvalidDataException("Voc header id is bogus - expected: " +
(~vfh.Version + 0x1234).ToString("X") + " but value is : " + vfh.ID.ToString("X")); (~vfh.Version + 0x1234).ToString("X") + " but value is : " + vfh.ID.ToString("X"));
@@ -271,7 +272,8 @@ namespace OpenRA.Mods.Common.AudioLoaders
void Rewind() void Rewind()
{ {
currentBlock = (IEnumerator<VocBlock>)blocks.GetEnumerator(); currentBlock = ((IEnumerable<VocBlock>)blocks).GetEnumerator();
currentBlockEnded = false;
samplesLeftInBlock = 0; samplesLeftInBlock = 0;
samplePosition = 0; samplePosition = 0;
@@ -284,9 +286,10 @@ namespace OpenRA.Mods.Common.AudioLoaders
return; 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) int FillBuffer(int maxSamples)
{ {
@@ -324,6 +327,7 @@ namespace OpenRA.Mods.Common.AudioLoaders
samplesLeftInBlock = currentBlock.Current.SampleBlock.Samples; samplesLeftInBlock = currentBlock.Current.SampleBlock.Samples;
return; return;
} }
currentBlockEnded = true;
} }
} }