Jelajahi Sumber

fixed null reference exception.

Vicente Penades 6 tahun lalu
induk
melakukan
7f57937a44

+ 8 - 4
src/SharpGLTF.Toolkit/Schema2/MaterialExtensions.cs

@@ -272,10 +272,14 @@ namespace SharpGLTF.Schema2
             if (dstChannel.Texture == null) dstChannel.UseTexture();
 
             dstChannel.Texture.CoordinateSet = srcChannel.TextureCoordinate;
-            dstChannel.Texture.MinFilter = srcChannel.TextureSampler.MinFilter;
-            dstChannel.Texture.MagFilter = srcChannel.TextureSampler.MagFilter;
-            dstChannel.Texture.WrapS = srcChannel.TextureSampler.WrapS;
-            dstChannel.Texture.WrapT = srcChannel.TextureSampler.WrapT;
+
+            if (srcChannel.TextureSampler != null)
+            {
+                dstChannel.Texture.MinFilter = srcChannel.TextureSampler.MinFilter;
+                dstChannel.Texture.MagFilter = srcChannel.TextureSampler.MagFilter;
+                dstChannel.Texture.WrapS = srcChannel.TextureSampler.WrapS;
+                dstChannel.Texture.WrapT = srcChannel.TextureSampler.WrapT;
+            }
 
             var srcXform = srcChannel.TextureTransform;
 

+ 7 - 3
tests/SharpGLTF.Tests/Scenes/SceneBuilderTests.cs

@@ -311,6 +311,7 @@ namespace SharpGLTF.Scenes
         }
 
 
+        [TestCase("Avocado.glb")]
         [TestCase("RiggedFigure.glb")]
         [TestCase("RiggedSimple.glb")]
         [TestCase("BoxAnimated.glb")]
@@ -351,10 +352,13 @@ namespace SharpGLTF.Scenes
             modelSrc.AttachToCurrentTest(path + "_src" + ".obj");
             modelBis.AttachToCurrentTest(path + "_bis" + ".obj");
 
-            modelSrc.AttachToCurrentTest(path + "_src_at01" + ".obj", modelSrc.LogicalAnimations[0], 0.1f);
+            if (modelSrc.LogicalAnimations.Count > 0)
+            {
+                modelSrc.AttachToCurrentTest(path + "_src_at01" + ".obj", modelSrc.LogicalAnimations[0], 0.1f);
 
-            if (modelBis.LogicalAnimations.Count > 0)
-                modelBis.AttachToCurrentTest(path + "_bis_at01" + ".obj", modelBis.LogicalAnimations[0], 0.1f);
+                if (modelBis.LogicalAnimations.Count > 0)
+                    modelBis.AttachToCurrentTest(path + "_bis_at01" + ".obj", modelBis.LogicalAnimations[0], 0.1f);
+            }
         }
 
     }