From 23fe0658a61df8f3fad302ae11561bf9b741a5f8 Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Sun, 20 Mar 2016 12:45:19 +0100 Subject: [PATCH 1/2] Fixed a NPE when Serializing a Spline without points. Also fixed a Typo. --- .../src/main/java/com/jme3/math/Spline.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/math/Spline.java b/jme3-core/src/main/java/com/jme3/math/Spline.java index 041baa0ba..8bf7bac5d 100644 --- a/jme3-core/src/main/java/com/jme3/math/Spline.java +++ b/jme3-core/src/main/java/com/jme3/math/Spline.java @@ -90,7 +90,7 @@ public class Spline implements Savable { type = splineType; this.curveTension = curveTension; this.cycle = cycle; - this.computeTotalLentgh(); + this.computeTotalLength(); } /** @@ -116,7 +116,7 @@ public class Spline implements Savable { this.controlPoints.addAll(controlPoints); this.curveTension = curveTension; this.cycle = cycle; - this.computeTotalLentgh(); + this.computeTotalLength(); } /** @@ -144,7 +144,7 @@ public class Spline implements Savable { this.weights[i] = controlPoint.w; } CurveAndSurfaceMath.prepareNurbsKnots(knots, basisFunctionDegree); - this.computeTotalLentgh(); + this.computeTotalLength(); } private void initCatmullRomWayPoints(List list) { @@ -186,7 +186,7 @@ public class Spline implements Savable { controlPoints.add(controlPoints.get(0).clone()); } if (controlPoints.size() > 1) { - this.computeTotalLentgh(); + this.computeTotalLength(); } } @@ -197,7 +197,7 @@ public class Spline implements Savable { public void removeControlPoint(Vector3f controlPoint) { controlPoints.remove(controlPoint); if (controlPoints.size() > 1) { - this.computeTotalLentgh(); + this.computeTotalLength(); } } @@ -209,7 +209,7 @@ public class Spline implements Savable { /** * This method computes the total length of the curve. */ - private void computeTotalLentgh() { + private void computeTotalLength() { totalLength = 0; float l = 0; if (segmentsLength == null) { @@ -317,7 +317,7 @@ public class Spline implements Savable { public void setCurveTension(float curveTension) { this.curveTension = curveTension; if(type==SplineType.CatmullRom && !getControlPoints().isEmpty()) { - this.computeTotalLentgh(); + this.computeTotalLength(); } } @@ -342,7 +342,7 @@ public class Spline implements Savable { controlPoints.add(controlPoints.get(0)); } this.cycle = cycle; - this.computeTotalLentgh(); + this.computeTotalLength(); } else { this.cycle = cycle; } @@ -369,7 +369,7 @@ public class Spline implements Savable { */ public void setType(SplineType type) { this.type = type; - this.computeTotalLentgh(); + this.computeTotalLength(); } /** @@ -435,9 +435,13 @@ public class Spline implements Savable { OutputCapsule oc = ex.getCapsule(this); oc.writeSavableArrayList((ArrayList) controlPoints, "controlPoints", null); oc.write(type, "type", SplineType.CatmullRom); - float list[] = new float[segmentsLength.size()]; - for (int i = 0; i < segmentsLength.size(); i++) { - list[i] = segmentsLength.get(i); + + float list[] = null; + if (segmentsLength != null) { + list = new float[segmentsLength.size()]; + for (int i = 0; i < segmentsLength.size(); i++) { + list[i] = segmentsLength.get(i); + } } oc.write(list, "segmentsLength", null); From 8477fa781b210c847e0f2845d48cb46bc518569d Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Sun, 20 Mar 2016 20:25:39 +0100 Subject: [PATCH 2/2] Fixed another NPE when missing serialized waypoints and fixed having different names for write/read --- jme3-core/src/main/java/com/jme3/math/Spline.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/math/Spline.java b/jme3-core/src/main/java/com/jme3/math/Spline.java index 8bf7bac5d..2220ea8b7 100644 --- a/jme3-core/src/main/java/com/jme3/math/Spline.java +++ b/jme3-core/src/main/java/com/jme3/math/Spline.java @@ -458,7 +458,7 @@ public class Spline implements Savable { public void read(JmeImporter im) throws IOException { InputCapsule in = im.getCapsule(this); - controlPoints = (ArrayList) in.readSavableArrayList("wayPoints", null); + controlPoints = (ArrayList) in.readSavableArrayList("controlPoints", new ArrayList()); /* Empty List as default, prevents null pointers */ float list[] = in.readFloatArray("segmentsLength", null); if (list != null) { segmentsLength = new ArrayList();