Skip to content

Commit

Permalink
Merge pull request ExOK#59 from hacktic-dev/celeste64nulltextures
Browse files Browse the repository at this point in the history
Prevent crash when gltf texture name is null
  • Loading branch information
NoelFB authored Feb 5, 2024
2 parents 1edd128 + fae87e5 commit 223862e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Source/Graphics/SkinnedTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct MeshPrimitive
public readonly DefaultMaterial[] Materials;

// only used while loading, cleared afterwards
private readonly Dictionary<string, Image> images = [];
private readonly Dictionary<SharpGLTF.Memory.MemoryImage, Image> images = [];

public SkinnedTemplate(SharpGLTF.Schema2.ModelRoot model)
{
Expand All @@ -33,7 +33,7 @@ public SkinnedTemplate(SharpGLTF.Schema2.ModelRoot model)
{
using var stream = new MemoryStream(logicalImage.Content.Content.ToArray());
var img = new Image(stream);
images[logicalImage.Name] = img;
images.Add(logicalImage.Content, img);
}

// All Materials use the default material
Expand Down Expand Up @@ -90,9 +90,9 @@ public SkinnedTemplate(SharpGLTF.Schema2.ModelRoot model)
public void ConstructResources()
{
// create all the textures and clear the list of images we had loaded
var textures = new Dictionary<string, Texture>();
foreach (var (name, image) in images)
textures[name] = new Texture(image);
var textures = new Dictionary<SharpGLTF.Memory.MemoryImage, Texture>();
foreach (var image in images)
textures[image.Key] = new Texture(image.Value);
images.Clear();

// create all the materials, find their textures
Expand All @@ -106,7 +106,7 @@ public void ConstructResources()
foreach (var channel in logicalMat.Channels)
if (channel.Texture != null &&
channel.Texture.PrimaryImage != null &&
textures.TryGetValue(channel.Texture.PrimaryImage.Name, out var texture))
textures.TryGetValue(channel.Texture.PrimaryImage.Content, out var texture))
{
Materials[i].Texture = texture;
break;
Expand Down

0 comments on commit 223862e

Please sign in to comment.