Skip to content

Commit

Permalink
Check if texture diffuse ids exists before access
Browse files Browse the repository at this point in the history
  • Loading branch information
Luzifix committed Aug 2, 2024
1 parent 3e6016a commit db5256a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ADTMeta/Steps/TexMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void Generate()
Console.WriteLine("[INFO] Generating texture meta");
Load();

Parallel.ForEach(ListFile.NameMap.Where(l => l.Value.EndsWith("_tex0.adt")), entry =>
Parallel.ForEach(ListFile.NameMap.Where(l => l.Value == "world/maps/newracestartzone/newracestartzone_21_34_tex0.adt" && l.Value.EndsWith("_tex0.adt")), entry =>
{
if (!CASC.Instance.FileExists(entry.Key))
return;
Expand Down Expand Up @@ -109,15 +109,15 @@ private static void CollectTextureMaterial(TerrainTexture terrainTexture)

foreach (var chunk in terrainTexture.Chunks)
{
if (chunk.TerrainMaterials == null || chunk.TerrainMaterials.TerrainMaterialIds == null || terrainTexture.TextureHeightIds == null || terrainTexture.TextureHeightIds.Textures == null)
if (chunk.TerrainMaterials == null || chunk.TerrainMaterials.TerrainMaterialIds == null || terrainTexture.TextureDiffuseIds == null || terrainTexture.TextureDiffuseIds.Textures == null)
continue;

for (byte i = 0; i < chunk.TerrainMaterials.TerrainMaterialIds.Length; i++)
{
if (chunk.TerrainMaterials.TerrainMaterialIds[i] == 0)
continue;

if (terrainTexture.TextureDiffuseIds.Textures[i] == 0)
if (terrainTexture.TextureDiffuseIds.Textures.Count() < (i+1) || terrainTexture.TextureDiffuseIds.Textures[i] == 0)
continue;

if (_textureMaterialMap.TryGetValue((int)terrainTexture.TextureDiffuseIds.Textures[i], out var existingInfo))
Expand Down Expand Up @@ -157,6 +157,9 @@ private static void CollectGroundEffects(TerrainTexture terrainTexture)
if (layer.EffectID == 0)
continue;

if (terrainTexture.TextureDiffuseIds.Textures.Count() < ((int)layer.TextureID + 1))
continue;

var textureId = (int)terrainTexture.TextureDiffuseIds.Textures[(int)layer.TextureID];
if (textureId <= 0)
continue;
Expand Down

0 comments on commit db5256a

Please sign in to comment.