FilterPostProcessor screen gets stuck when window resizes

I’m using a FilterPostProcessor like so (in an AppState) (lifted straight from TestCartoonEdge.java):

@Override
public void create() {
    super.create();
    if (app.getRenderer().getCaps().contains(Caps.GLSL100)) {
        FilterPostProcessor fpp = new FilterPostProcessor(app.getAssetManager());
        int numSamples = app.getContext().getSettings().getSamples();
        if (numSamples > 0) {
            fpp.setNumSamples(numSamples);
        }
        CartoonEdgeFilter toon = new CartoonEdgeFilter();
        toon.setEdgeColor(ColorRGBA.Blue);
        toon.setEdgeIntensity(1.0f);
        toon.setEdgeWidth(1.0f);
        fpp.addFilter(toon);
        app.getViewPort().addProcessor(fpp);
    }
    // update camera to make sure it is set up properly
    updateCamera();
}

When the window loses focus the screen stops updating (this is normal). when I re focus the screen the renderer has stopped working for my scene, it just stays the same, or black if I try to resize. I can see the stats view updating but that is it.

If I remove the fpp then it works as I expect (but without the fpp obviously).

Am I missing something simple?

version 3.1.0-beta1

UPDATE

In fact I incorrectly stated that the issue persists when the window loses focus but actually it seems to only break when you resize the window. Or at least that is what I now observe from the above TestApplication code.

So i found this topic and in it it mentions that fpp.setNumSamples(numSamples); causes issues.

Sure enough if I remove that code it works, but is obviously aliased.

However what is not so obvious is this (bear with me): When the scene first loads (with my original code) it works up until the window loses focus. This code contains the call to fpp.setNumSamples(numSamples) even if I force it to set num samples to 4 then the FilterPostProcessor is still aliased, the scene is anti-aliased in the manner I expected, but still broken when the window loses focus.

UPDATE

I get the same problem exactly repeated if I use a different filter instead; I used RadialBlurFilter.

I would personally send a copy pastable sample. I guess the masters among us can then better help. Seems an easy thing to do.

1 Like

Righto, this is a full example that exhibits the problem (don’t forget, you need the jme3-effects jar):

import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.CartoonEdgeFilter;
import com.jme3.renderer.Caps;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;

public class TestApplication extends SimpleApplication {

    public static void main(String[] args) {
        TestApplication game = new TestApplication();
        game.setShowSettings(false);

        AppSettings settings = new AppSettings(true);
        settings.setResizable(true);
        settings.setSamples(4);
        game.setSettings(settings);

        game.start();
    }

    private TestApplication() {
        super(new StatsAppState());
    }

    @Override
    public void simpleInitApp() {
        inputManager.setCursorVisible(true);

        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);
        rootNode.attachChild(geom);

        if (renderer.getCaps().contains(Caps.GLSL100)) {
            FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
            int numSamples = context.getSettings().getSamples();
            if (numSamples > 0)
                fpp.setNumSamples(numSamples);
            CartoonEdgeFilter toon = new CartoonEdgeFilter();
            toon.setEdgeColor(ColorRGBA.Green);
            toon.setEdgeIntensity(1.0f);
            toon.setEdgeWidth(1.0f);
            fpp.addFilter(toon);
            viewPort.addProcessor(fpp);
        }
    }

    @Override
    public void simpleUpdate(float tpf) {
        rootNode.rotate(tpf, tpf / 2, tpf / 4);
    }

}

If you comment out the line settings.setSamples(4); then it works as expected. So I suspect a bug in the sampling code for filters or something.

Can anyone else see the same problem?

2 Likes

In fact I incorrectly stated that the issue persists when the window loses focus but actually it seems to only break when you resize the window. Or at least that is what I now observe from the above TestApplication code.

Thanks I’ll check it out.
What JME version do you use?

:wink:

Great test case, I wish people would do that all the time.
Fixed the issue here : Fixed an issue when resizing the viewport, with a FPP and antialiasin… · jMonkeyEngine/jmonkeyengine@619a323 · GitHub

Must have been there since a long time.
Thanks.

4 Likes