FrameBuffer cleaning problem

I use a frameBuffer and a viewPort to display a rear mirror.

It goes fine when I start a race and gives no problems when the cleaning code is executed, but when I then start a new race I get an exception.

This is the cleaning code:

public void clean() {

This is the exception:
java.lang.IllegalStateException: Framebuffer has erronous attachment.
at com.jme3.renderer.opengl.GLRenderer.checkFrameBufferError(
at com.jme3.renderer.opengl.GLRenderer.updateFrameBuffer(
at com.jme3.renderer.opengl.GLRenderer.setFrameBuffer(
at com.jme3.renderer.RenderManager.renderViewPort(
at com.jme3.renderer.RenderManager.render(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(

AL lib: (EE) alc_cleanup: 1 device not closed

It used to work on 3.0 (maybe by luck :D)… any idea what I’m doing wrong?

…seems like we are only seeing at most half the code then.

Ah, ok, here is the creation of the rear view mirror:

    public void initialize() {
        screen = game.getGameManager().getScreen();
        flyCamAppState = game.getStateManager().getState(FlyCamAppState.class);
        offCamera = new Camera(WIDTH, HEIGHT);

        reflectionView = game.getRenderManager().createPreView("Offscreen RearView", offCamera);
        reflectionView.setClearFlags(true, true, true);

        //setup framebuffer's cam
        offCamera.setFrustumPerspective(30, 2f, 1f, 500f);
        // create offscreen framebuffer
        offBuffer = new FrameBuffer(WIDTH, HEIGHT, 1);

        //setup framebuffer's texture
        offTex = new Texture2D(WIDTH, HEIGHT, Format.RGBA8);
//        offTex.setMinFilter(Texture.MinFilter.Trilinear);
//        offTex.setMagFilter(Texture.MagFilter.Bilinear);

        //setup framebuffer to use texture
        //set viewport to render to offscreen framebuffer

    private void displayRearMirror(){ 
        rearView = new Element(screen, "rearView",
                new Vector2f((screen.getWidth() - 5f), 40f),
                new Vector2f(WIDTH, HEIGHT),
                Vector4f.ZERO.clone(), "Interface/Textures/empty.png");
        rearView.getMaterial().setTexture("ColorMap", offTex);
        rearView.rotate(0, FastMath.PI, 0);

nb: a baseAppState take cares of calling the constructing/initializing and cleaning. At the end of a race, I detach all appStates… so my idea was that the cleaning method was the culprit.

It used to work on 3.0 (maybe by luck :D)

So you are using 3.1 and it works fine in the 3.0 ?
Besides it maybe some bug on the 3.1 what is must possible ( I could not use 3.1 yet for any of my games, too many bugs ), I would try to clean the camera as well and see what happens…
I had problems with cameras when using this type of custom rendering, the camera is part of the rendering, so you need to take care of it: [SOLVED] Cant move the camera when rendering to texture - #12 by wagfeliz

Yah worked without a glitch in 3.0.

I’ve made it work in 3.1 by adding this to the cleaning up:


I have no idea if it’s a good way but I don’t get an exception anymore and haven’t found new glitches. So unless told otherwise, I’m probably going to stick with it.

Thanks for your answers.

NB: haven’t set it as resolved yet because I’d be interested in being told if my solution is fine or if I’m opening myself to a world of troubles.