Fixed IllegalArgumentException when removing a LodControl from a spatial

LodControl throws an exception when the spatial being added to isn't a geometry, however, when the controls is removed it calls setSpatial with a null value triggering the exception throw. Now checking for this null value case.
fix-456
NemesisMate 8 years ago committed by GitHub
parent 080a89e14b
commit 88125da16d
  1. 8
      jme3-core/src/main/java/com/jme3/scene/control/LodControl.java

@ -121,11 +121,13 @@ public class LodControl extends AbstractControl implements Cloneable, JmeCloneab
@Override
public void setSpatial(Spatial spatial) {
if (!(spatial instanceof Geometry)) {
if (spatial != null && !(spatial instanceof Geometry)) {
throw new IllegalArgumentException("LodControl can only be attached to Geometry!");
}
super.setSpatial(spatial);
if(spatial != null) {
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
numLevels = mesh.getNumLodLevels();
@ -133,6 +135,10 @@ public class LodControl extends AbstractControl implements Cloneable, JmeCloneab
for (int i = numLevels - 1; i >= 0; i--) {
numTris[i] = mesh.getTriangleCount(i);
}
} else {
numLevels = 0;
numTris = null;
}
}
@Override

Loading…
Cancel
Save