Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NullPointerException in AnimLayer.update() #1730

Merged
merged 2 commits into from
Jan 7, 2022
Merged

Fix NullPointerException in AnimLayer.update() #1730

merged 2 commits into from
Jan 7, 2022

Conversation

capdevon
Copy link
Contributor

@capdevon capdevon commented Jan 5, 2022

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)

Edit:
Link to the forum post: https://hub.jmonkeyengine.org/t/v3-5-0-beta-testing/45209/17

Edit 2:
To facilitate the understanding of the problem I also add the explanation of the fix discussed on the forum and suggested by Ali-RS: "the currentAction should be copied into a local variable inside AnimLayer.update() because it might be changed, removed or replaced with new action in Action.interpolate(time)"

For clarity here is a sample code that can cause the exception:

class NonLoopingAction extends BaseAction {

    ...
     public boolean interpolate(double t) {
        var result = delegate.interpolate(t);
        if (!result) {
            composer.removeCurrentAction(AnimComposer.DEFAULT_LAYER);
        }
        return result;
    }
}

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)
@Ali-RS Ali-RS changed the title NullPointerException in AnimLayer.update() Fix NullPointerException in AnimLayer.update() Jan 6, 2022
@Ali-RS
Copy link
Member

Ali-RS commented Jan 6, 2022

Looks good to me, thank you @capdevon!

Unless there's substantial discussion, I plan to integrate this in about 24 hours.

@Ali-RS Ali-RS added the bug Something that is supposed to work, but doesn't. More severe than a "defect". label Jan 6, 2022
@Ali-RS Ali-RS added this to the v3.5.0 milestone Jan 6, 2022
@Ali-RS Ali-RS self-assigned this Jan 6, 2022
@stephengold
Copy link
Member

Does the choice of variable name count as substantial discussion?

@Ali-RS
Copy link
Member

Ali-RS commented Jan 7, 2022

Does the choice of variable name count as substantial discussion?

Yes, I think so.

Please continue the discussion about the variable name, I will delay the merge until we resolve it. Thanks!

@stephengold stephengold merged commit 33d9cdc into jMonkeyEngine:master Jan 7, 2022
@stephengold
Copy link
Member

Thanks @capdevon and @Ali-RS !

@Ali-RS Ali-RS removed their assignment Jan 7, 2022
stephengold pushed a commit that referenced this pull request Jan 9, 2022
* 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
@stephengold
Copy link
Member

Confirmed fixed in v3.5.0-beta6 ... https://hub.jmonkeyengine.org/t/v3-5-0-beta-testing/45209/26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants