ソースを参照

Fix NPE as reported in #1391
Also went ahead and added a similar check to the regular clone() method and a comment
about how it should probably be calling JmeCloner.

pspeed42 5 年 前
コミット
1c638f2763

+ 7 - 2
jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainPatch.java

@@ -931,6 +931,9 @@ public class TerrainPatch extends Geometry {
 
     @Override
     public TerrainPatch clone() {
+        // Note: this method should probably be using JmeCloner instead of manually
+        // cloning.  -pspeed:2020-08-21
+
         TerrainPatch clone = new TerrainPatch();
         clone.name = name.toString();
         clone.size = size;
@@ -946,7 +949,7 @@ public class TerrainPatch extends Geometry {
         clone.setLocalTranslation(getLocalTranslation().clone());
         Mesh m = clone.geomap.createMesh(clone.stepScale, Vector2f.UNIT_XY, clone.offset, clone.offsetAmount, clone.totalSize, false);
         clone.setMesh(m);
-        clone.setMaterial(material.clone());
+        clone.setMaterial(material == null ? null : material.clone());
         return clone;
     }
 
@@ -975,7 +978,9 @@ public class TerrainPatch extends Geometry {
         // not to clone it.  Terrain uses mutable textures and stuff so it's important
         // to clone it.  (At least that's my understanding and is evidenced by the old
         // clone code specifically cloning material.)  -pspeed
-        this.material = material.clone();
+        // Also note that Geometry will have potentially already cloned this but the pre-JmeCloner
+        // code didn't care about that extra garbage, either. -pspeed:2020-08-21
+        this.material = material == null ? null : material.clone();
     }
 
     protected void ensurePositiveVolumeBBox() {