When filters don't like each other…

Hi!
When adding a BloomFilter first and a WaterFilter short time after, the application crashes for some reason.
Exception:
[java]java.lang.UnsupportedOperationException: FrameBuffer already initialized.
at com.jme3.texture.FrameBuffer.setDepthTexture(FrameBuffer.java:400)
at com.jme3.post.FilterPostProcessor.initFilter(FilterPostProcessor.java:162)
at com.jme3.post.FilterPostProcessor.addFilter(FilterPostProcessor.java:109)
at mygame.Main.simpleUpdate(Main.java:56)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)[/java]
Code:
[java]public class Main extends SimpleApplication
{

private FilterPostProcessor filterPostProcessor;
private WaterFilter waterFilter;
private BloomFilter bloomFilter;
private float a = 100;

public static void main(String[] args)
{
    Main app = new Main();
    app.start();
}

@Override
public void simpleInitApp()
{
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    cam.setLocation(new Vector3f(10, 10, 0));
    cam.lookAt(geom.getWorldTranslation(), Vector3f.UNIT_Y);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    geom.setMaterial(mat);
    bloomFilter = new BloomFilter();
    waterFilter = new WaterFilter();
    filterPostProcessor = new FilterPostProcessor(assetManager);
    viewPort.addProcessor(filterPostProcessor);
    filterPostProcessor.addFilter(bloomFilter);
    rootNode.attachChild(geom);
}

@Override
public void simpleUpdate(float tpf)
{
    System.out.println(a);
    if (a-- < 0) //little countdown
    {
        filterPostProcessor.addFilter(waterFilter);
    }
}

}
[/java]

The other way around (first adding waterfilter and bloom after the short countdown) does not lead to a crash, but the framerate drops to 1.
Am I breaking a rule or something?
Btw this does also apply to other filters.
Ideas?

Thank you.

[java]
if (a– < 0) //little countdown
{
filterPostProcessor.addFilter(waterFilter);
}
[/java]

Even without the ‘-’ typo, this is not doing what you think it’s doing. Unless your intent is to add an infinite number of water filters after 100 frames.

1 Like
@pspeed said:

Even without the ‘-’ typo, this is not doing what you think it’s doing. Unless your intent is to add an infinite number of water filters after 100 frames.

This amuses me.

Hey! It’s Friday! Leave me alone. :stuck_out_tongue:

it’s
[java]
if(a–<0) … [/java] I don’t know why it copied that wrong.

Unless your intent is to add an infinite number of water filters after 100 frames.
Yeah that was stupid, still it does not explain why it crashes at the first WaterFilter, the result does not change using this code: [java] if (a - - < 0) //little countdown { if (!filterPostProcessor.getFilterList().contains(waterFilter)) { filterPostProcessor.addFilter(waterFilter); } }[/java]

JESUS CHRIST I can not write two - in java style?
You know what I mean, the opposite of ++

The double - has to do with the HTML comment tag.

It’s still amusing. :stuck_out_tongue:

I don’t know why it crashes… but also putting a water filter after the bloom doesn’t really make sense either. Bloom should be near the end since it should operate on the completed frame (or as close to it as possible). I mean logically.

@madjack said: The double - has to do with the HTML comment tag.

It’s still amusing. :stuck_out_tongue:


Yeah, totally… :-[

@pspeed said: I don't know why it crashes... but also putting a water filter _after_ the bloom doesn't really make sense either. Bloom should be near the end since it should operate on the completed frame (or as close to it as possible). I mean logically.
Did not think of that, makes sense, still curious.