From 6c4e8010f252a2fb59b63b05dbd2b636255ffd34 Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Wed, 17 Feb 2016 23:45:27 +0100 Subject: [PATCH] Fixes the bug of shallow copies when cloning lights (See http://hub.jmonkeyengine.org/t/what-is-the-expected-meaning-of-light-clone/35100 ) --- .../src/main/java/com/jme3/light/DirectionalLight.java | 6 ++++++ jme3-core/src/main/java/com/jme3/light/Light.java | 4 +++- jme3-core/src/main/java/com/jme3/light/PointLight.java | 7 +++++++ jme3-core/src/main/java/com/jme3/light/SpotLight.java | 8 ++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java b/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java index b1abb65cf..018bd127e 100644 --- a/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java +++ b/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java @@ -146,4 +146,10 @@ public class DirectionalLight extends Light { direction = (Vector3f) ic.readSavable("direction", null); } + @Override + public DirectionalLight clone() { + DirectionalLight l = (DirectionalLight)super.clone(); + l.direction = direction.clone(); + return l; + } } diff --git a/jme3-core/src/main/java/com/jme3/light/Light.java b/jme3-core/src/main/java/com/jme3/light/Light.java index afef33b1d..6181037e9 100644 --- a/jme3-core/src/main/java/com/jme3/light/Light.java +++ b/jme3-core/src/main/java/com/jme3/light/Light.java @@ -228,7 +228,9 @@ public abstract class Light implements Savable, Cloneable { @Override public Light clone(){ try { - return (Light) super.clone(); + Light l = (Light) super.clone(); + l.color = color.clone(); + return l; } catch (CloneNotSupportedException ex) { throw new AssertionError(); } diff --git a/jme3-core/src/main/java/com/jme3/light/PointLight.java b/jme3-core/src/main/java/com/jme3/light/PointLight.java index 4b5224c30..23901e52f 100644 --- a/jme3-core/src/main/java/com/jme3/light/PointLight.java +++ b/jme3-core/src/main/java/com/jme3/light/PointLight.java @@ -241,4 +241,11 @@ public class PointLight extends Light { this.invRadius = 0; } } + + @Override + public PointLight clone() { + PointLight p = (PointLight)super.clone(); + p.position = position.clone(); + return p; + } } diff --git a/jme3-core/src/main/java/com/jme3/light/SpotLight.java b/jme3-core/src/main/java/com/jme3/light/SpotLight.java index bc1335b5b..f9750cdac 100644 --- a/jme3-core/src/main/java/com/jme3/light/SpotLight.java +++ b/jme3-core/src/main/java/com/jme3/light/SpotLight.java @@ -448,5 +448,13 @@ public class SpotLight extends Light { this.invSpotRange = 0; } } + + @Override + public SpotLight clone() { + SpotLight s = (SpotLight)super.clone(); + s.direction = direction.clone(); + s.position = position.clone(); + return s; + } }