소스 검색

Modified Line to keep its own start/end instances. This is less of a surprise if
a user later chooses to call updatePoints() after having created the line with
JME constants... since updatePoints() would actually call set() instead of just
replacing the references. The constructor and updatePoints() should match and I chose
to err on the side of caution and make them both operate on local instances.

Paul Speed 5 년 전
부모
커밋
c23f28b51c
1개의 변경된 파일6개의 추가작업 그리고 6개의 파일을 삭제
  1. 6 6
      jme3-core/src/main/java/com/jme3/scene/shape/Line.java

+ 6 - 6
jme3-core/src/main/java/com/jme3/scene/shape/Line.java

@@ -49,8 +49,8 @@ import java.nio.FloatBuffer;
  */
 public class Line extends Mesh {
 
-    private Vector3f start;
-    private Vector3f end;
+    private Vector3f start = new Vector3f();
+    private Vector3f end = new Vector3f();
 
     /**
      * No-argument constructor needed by SavableClassUtil.
@@ -64,8 +64,8 @@ public class Line extends Mesh {
     }
 
     protected void updateGeometry(Vector3f start, Vector3f end) {
-        this.start = start;
-        this.end = end;
+        this.start.set(start);
+        this.end.set(end);
         setBuffer(Type.Position, 3, new float[]{start.x,    start.y,    start.z,
                                                 end.x,      end.y,      end.z,});
 
@@ -126,7 +126,7 @@ public class Line extends Mesh {
         super.read(im);
         InputCapsule in = im.getCapsule(this);
 
-        start = (Vector3f) in.readSavable("startVertex", null);
-        end = (Vector3f) in.readSavable("endVertex", null);
+        start = (Vector3f) in.readSavable("startVertex", start);
+        end = (Vector3f) in.readSavable("endVertex", end);
     }
 }