Skip to content

Commit 4fffb5c

Browse files
committed
Added guard clause around shader data import.
1 parent 110542b commit 4fffb5c

File tree

1 file changed

+10
-2
lines changed
  • xivModdingFramework/Materials/FileTypes

1 file changed

+10
-2
lines changed

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
using HelixToolkit.SharpDX.Core;
1718
using SharpDX;
1819
using System;
1920
using System.Collections.Generic;
@@ -532,9 +533,16 @@ await Task.Run((Func<Task>)(async () =>
532533
var offset = shaderParam.Offset;
533534
var size = shaderParam.Size;
534535
shaderParam.Bytes = new List<byte>();
535-
for(var idx = offset; idx < offset + size; idx++)
536+
if (offset + size <= shaderBytes.Length)
536537
{
537-
shaderParam.Bytes.Add(shaderBytes[idx]);
538+
for (var idx = offset; idx < offset + size; idx++)
539+
{
540+
shaderParam.Bytes.Add(shaderBytes[idx]);
541+
}
542+
} else
543+
{
544+
// Just use a blank array if we have missing/invalid shader data.
545+
shaderParam.Bytes = new List<byte>(new byte[size]);
538546
}
539547
}
540548

0 commit comments

Comments
 (0)