Fix some unnecessary crashes on mtrl.

This commit is contained in:
Ottermandias 2022-09-25 18:32:31 +02:00
parent b359c18360
commit 35c6e0ec88
3 changed files with 24 additions and 9 deletions

View file

@ -143,6 +143,7 @@ public partial class MtrlFile : IWritable
public RowArray Rows;
public string Name;
public ushort Index;
public bool HasRows;
}
public unsafe struct ColorDyeSet
@ -305,7 +306,15 @@ public partial class MtrlFile : IWritable
AdditionalData = r.ReadBytes( additionalDataSize );
for( var i = 0; i < ColorSets.Length; ++i )
{
ColorSets[ i ].Rows = r.ReadStructure< ColorSet.RowArray >();
if( stream.Position + ColorSet.RowArray.NumRows * ColorSet.Row.Size <= stream.Length )
{
ColorSets[ i ].Rows = r.ReadStructure< ColorSet.RowArray >();
ColorSets[ i ].HasRows = true;
}
else
{
ColorSets[i].HasRows = false;
}
}
for( var i = 0; i < ColorDyeSets.Length; ++i )