[SOLVED] Feedback loop issue (shader)

Every time I try to draw a quad with a shader, I get an error on Chrome:

1190937:1 [.WebGL-0xb000ee6300] GL_INVALID_OPERATION: Feedback loop formed between Framebuffer and active Texture.

This is because the shader thinks I am trying to read the data from a texture that is currently being written to, even though I don’t. Do I need to explicitly change the FBO or unbind the texture? Both drawFullscreenQuad and drawQuadWithShader are giving me this.

Here are my steps:

const texture = new pc.Texture(...);
const target = new pc.RenderTarget(...); // using new texture
const shader = new pc.Shader(...);

pc.drawQuadWithShader(device, target, shader);

@mvaligursky any advice?

I can write/read pixel data from a texture by using device.setRenderTarget without errors, e.g.:

const old = device.renderTarget;
device.setRenderTarget(target);
device.updateBegin();
// process
device.readPixels(0, 0, width, height, colors);
device.updateEnd();
device.setRenderTarget(old);

Nothing obvious seems wrong here. We use this few times internally in the engine without problems too.

Do you use framebuffer as a texture at all anywhere? Maybe postprocessing / grabPass? Try to disable it.
Try using the debug engine - we have some log messages to catch it as well.

4 Likes

The issue was in me passing a wrong texture to the shader. If you are getting this error, make sure your shader samples the correct texture. For example, this can cause an issue, if your uniform gets incorrect color buffer:

material.setParameter('my_texture', renderTarget.colorBuffer);
2 Likes