(Solved) Null effect info on button press

I am working on some effects tied to Lemur’s styling when I bumped into an npe when trying to access the effect info passed during effect.create()

public void simpleInitApp() {
        Styles styles = GuiGlobals.getInstance().getStyles();
        Attributes attrs;
        attrs = styles.getSelector("button", "test");
        Effect testEffect = new AbstractEffect(){
            public Animation create(Object t, EffectInfo ei) {
                System.out.println("Effect Info: "+ei);
                System.out.println("Here is the npe: "+ei.toString());
                return new TweenAnimation(Tweens.delay(0));
        Map<String, Effect> buttonEffects = new HashMap<>();
        buttonEffects.put(Button.EFFECT_PRESS, testEffect);
        attrs.set("effects", buttonEffects);
        //test button
        Button testButton = new Button("Test", "test");
        testButton.setLocalTranslation(cam.getWidth()/2, cam.getHeight()/2, 0);

This is the console

Effect Info: null
Jan 01, 2020 1:05:24 AM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
	at test.TestEffect$1.create(TestEffect.java:43)
	at com.simsilica.lemur.effect.EffectControl.runEffect(EffectControl.java:134)
	at com.simsilica.lemur.effect.EffectControl.runEffect(EffectControl.java:115)
	at com.simsilica.lemur.Panel.runEffect(Panel.java:363)
	at com.simsilica.lemur.Button.setPressed(Button.java:349)
	at com.simsilica.lemur.Button$ButtonMouseHandler.mouseButtonEvent(Button.java:427)
	at com.simsilica.lemur.event.MouseEventControl.mouseButtonEvent(MouseEventControl.java:122)
	at com.simsilica.lemur.event.PickEventSession.buttonEvent(PickEventSession.java:693)
	at com.simsilica.lemur.event.MouseAppState.dispatch(MouseAppState.java:98)
	at com.simsilica.lemur.event.MouseAppState$MouseObserver.onMouseButtonEvent(MouseAppState.java:114)
	at com.jme3.input.InputManager.processQueue(InputManager.java:841)
	at com.jme3.input.InputManager.update(InputManager.java:917)
	at com.jme3.app.LegacyApplication.update(LegacyApplication.java:724)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:246)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Thread.java:748)

Ultimately I was trying to use 1 effect object for multiple effect keys (ie effect_press & effect_release) similar to how the glass style handles button commands. I realize that probably isn’t the best practice for effects but this seemed like a bug regardless.

I think maybe there is a misunderstanding of what that EffectInfo is supposed to be.

From the javadoc:

Creates a new animation task that will replace any existing animation task for this Effect’s channel. The last run animation is passed as the ‘existing’ parameter that this factory method can use to see if the previous one is still running and adjust accordingly. (For example, a close window animation might do something different if the open window animation hadn’t completed yet.) By default, if the caller requests it when running the effect, the EffectControl will attempt to manage this by fast forwarding the new animation to catch up to what was left of the old animation.

So it’s normal for this parameter to be null unless there was an effect run previously on the same channel. It’s meant for coordinating things like open/close or down/up animations that must do something different if the paired animation is still in the middle.

1 Like