LodControl cloning bug (nightly)

Decided to give the new LOD generator a try and got stuck when trying to add the LodControl:
[java]
[…] java.lang.IllegalStateException: This control has already been added to a Spatial
at com.jme3.scene.control.AbstractControl.setSpatial(AbstractControl.java:58)
at com.jme3.scene.control.LodControl.setSpatial(LodControl.java:124)
at com.jme3.scene.Spatial.clone(Spatial.java:1186)
at com.jme3.scene.Geometry.clone(Geometry.java:440)
at com.jme3.scene.Geometry.clone(Geometry.java:60)
at com.jme3.scene.Spatial.clone(Spatial.java:1172)
at com.jme3.scene.Node.clone(Node.java:565)
at com.jme3.scene.Node.clone(Node.java:60)
at com.jme3.scene.Spatial.clone(Spatial.java:1172)
at com.jme3.scene.Node.clone(Node.java:565)
at com.jme3.scene.Node.clone(Node.java:60)
at com.jme3.scene.Spatial.clone(Spatial.java:1172)
at com.jme3.scene.Node.clone(Node.java:565)
at com.jme3.scene.Node.clone(Node.java:60)
at com.jme3.scene.Spatial.clone(Spatial.java:1214)
at com.jme3.scene.Spatial.clone(Spatial.java:66)
at com.jme3.asset.CloneableAssetProcessor.createClone(CloneableAssetProcessor.java:48)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:327)
[…]
[/java]

I was first baking the LODs and saving the geometry to a j3o, then loading it, but simply cloning the geometry is enough to reproduce the exception.

Test case: http://pastebin.com/bmVpStbT
I’m using a nightly build I compiled myself a few minutes ago, I can check if it happens in the latest Stable relase if needed.

Thanks in advance to anyone looking into this :slight_smile:

Yeah, the LodControl’s cloneForSpatial method is broken since it doesn’t call the super class cloneForSpatial() method.

[java]
public Control cloneForSpatial(Spatial spatial) {
try {
LodControl clone = (LodControl) super.clone();
clone.lastDistance = 0;
clone.lastLevel = 0;
clone.numTris = numTris != null ? numTris.clone() : null;
return clone;
} catch (CloneNotSupportedException ex) {
throw new AssertionError();
}
}
[/java]

I don’t have time to fix it but maybe some else will.

This:
(LodControl) super.clone();

Should be:
(LodControl)super.cloneForSpatial(spatial);

1 Like

uh ok.
I’ll look into it.

bump
pspeed’s fix works.

1 Like

ho sorry I forgot.
That’s fixed in last SVN
Thanks for the report (and the bump :wink: )

1 Like

Cheers, thanks for the fix :slight_smile: