Skip to content

Commit

Permalink
Avoid infinite loop, still not a great fix but non-crashing Accumulator
Browse files Browse the repository at this point in the history
  • Loading branch information
mcslee committed Aug 21, 2023
1 parent 2a26394 commit d2d23e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/heronarts/lx/modulator/Accumulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ public Accumulator(String label, LXParameter velocity) {

@Override
protected double computeValue(double deltaMs) {
float currentValue = getValuef();
final float currentValue = getValuef();
float amount = (float) (deltaMs * this.velocity.getValue());
if (amount == 0) {
return currentValue;
}
float newValue = currentValue + this.sign * amount;
if (currentValue == newValue || Float.isInfinite(newValue)) {
if ((currentValue == newValue) || Float.isInfinite(newValue)) {
if (++this.collisions > 3) {
this.collisions = 0;
this.sign = -this.sign;
int i = 0;
do {
newValue = currentValue + this.sign * amount;
amount *= 10;
} while (newValue == currentValue);
} while ((newValue == currentValue) && (i++ < 10));
}
}
return newValue;
Expand Down

0 comments on commit d2d23e1

Please sign in to comment.