Jelajahi Sumber

Fix NullPointerException in AnimLayer.update() (#1730)

* NullPointerException in AnimLayer.update()

java.lang.NullPointerException: Cannot invoke
"com.jme3.anim.tween.action.Action.setMask(com.jme3.anim.AnimationMask)"
because "this.currentAction" is null
        at com.jme3.anim.AnimLayer.update(AnimLayer.java:209)
        at com.jme3.anim.AnimComposer.controlUpdate(AnimComposer.java:391)
        at com.jme3.scene.control.AbstractControl.update(AbstractControl.java:118)
        at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:743)
        at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:890)
        at com.jme3.scene.Node.updateLogicalState(Node.java:228)
        at com.jme3.scene.Node.updateLogicalState(Node.java:239)

* rename runningAction -> action
Wyatt Gillette 3 tahun lalu
induk
melakukan
33d9cdcfdd
1 mengubah file dengan 7 tambahan dan 6 penghapusan
  1. 7 6
      jme3-core/src/main/java/com/jme3/anim/AnimLayer.java

+ 7 - 6
jme3-core/src/main/java/com/jme3/anim/AnimLayer.java

@@ -189,24 +189,25 @@ public class AnimLayer implements JmeCloneable {
      *     current Action, in seconds
      */
     void update(float appDeltaTimeInSeconds) {
-        if (currentAction == null) {
+        Action action = currentAction;
+        if (action == null) {
             return;
         }
 
-        double speedup = currentAction.getSpeed() * composer.getGlobalSpeed();
+        double speedup = action.getSpeed() * composer.getGlobalSpeed();
         double scaledDeltaTime = speedup * appDeltaTimeInSeconds;
         time += scaledDeltaTime;
 
         // wrap negative times to the [0, length] range:
         if (time < 0.0) {
-            double length = currentAction.getLength();
+            double length = action.getLength();
             time = (time % length + length) % length;
         }
 
         // update the current Action, filtered by this layer's mask:
-        currentAction.setMask(mask);
-        boolean running = currentAction.interpolate(time);
-        currentAction.setMask(null);
+        action.setMask(mask);
+        boolean running = action.interpolate(time);
+        action.setMask(null);
 
         if (!running) { // went past the end of the current Action
             time = 0.0;