Explorar o código

- change Spatial and AbstractControl so that control.setSpatial doesn't have to be called in Control.cloneForSpatial but the engine also doesn't throw an exception if it does

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10367 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
nor..67 %!s(int64=12) %!d(string=hai) anos
pai
achega
b17fbf1f49

+ 3 - 1
engine/src/core/com/jme3/scene/Spatial.java

@@ -1182,7 +1182,9 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
 
             clone.controls = new SafeArrayList<Control>(Control.class);
             for (int i = 0; i < controls.size(); i++) {
-                clone.controls.add(controls.get(i).cloneForSpatial(clone));
+                Control newControl = controls.get(i).cloneForSpatial(clone);
+                newControl.setSpatial(this);
+                clone.controls.add(newControl);
             }
 
             if (userData != null) {

+ 1 - 1
engine/src/core/com/jme3/scene/control/AbstractControl.java

@@ -54,7 +54,7 @@ public abstract class AbstractControl implements Control {
     }
 
     public void setSpatial(Spatial spatial) {
-        if (this.spatial != null && spatial != null) {
+        if (this.spatial != null && spatial != null && spatial != this.spatial) {
             throw new IllegalStateException("This control has already been added to a Spatial");
         }   
         this.spatial = spatial;