Skip to content
27 changes: 11 additions & 16 deletions jme3-core/src/main/java/com/jme3/scene/Spatial.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,16 +772,7 @@ public void runControlRender(RenderManager rm, ViewPort vp) {
* @see Spatial#removeControl(java.lang.Class)
*/
public void addControl(Control control) {
boolean before = requiresUpdates();
controls.add(control);
control.setSpatial(this);
boolean after = requiresUpdates();
// If the requirement to be updated has changed,
// then we need to let the parent node know, so it
// can rebuild its update list.
if (parent != null && before != after) {
parent.invalidateUpdateList();
}
addControlAt(controls.size(), control);
}

/**
Expand All @@ -807,13 +798,17 @@ public void addControlAt(int index, Control control) {
throw new IllegalStateException("Control is already added here.");
}

addControl(control); // takes care of the bookkeeping

if (index < numControls) { // re-arrange the list directly
boolean success = controls.remove(control);
assert success : "Surprising control remove failure. " + control.getClass().getSimpleName() + " from spatial " + getName();
controls.add(index, control);
boolean before = requiresUpdates();
controls.add(index, control);
control.setSpatial(this);
boolean after = requiresUpdates();
// If the requirement to be updated has changed,
// then we need to let the parent node know, so it
// can rebuild its update list.
if (parent != null && before != after) {
parent.invalidateUpdateList();
}

}

/**
Expand Down
Loading