Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command fails if buffers for unrelated attributes are destroyed #483

Closed
rreusser opened this issue May 13, 2018 · 1 comment
Closed

Command fails if buffers for unrelated attributes are destroyed #483

rreusser opened this issue May 13, 2018 · 1 comment

Comments

@rreusser
Copy link
Member

rreusser commented May 13, 2018

I think I've encountered a cleanup bug in which attributes are not disabled so that subsequent, unrelated commands expect attributes used by previous commands to be available forever.

Reproduction: https://codepen.io/rsreusser/pen/QrxQzj

Reproduction code is listed at the bottom. The timeouts help make the sequence clear but are not required. The logs look like:

invoke command with two attributes
destroy color buffer
invoke command with one attribute
(unknown) WebGL: INVALID_OPERATION: drawArrays: no buffer is bound to enabled attribute

Solutions that cause the second command to succeed:

  1. don't call the first command
  2. don't destroy the color buffer used by the first command
  3. add a second attribute to the second command

This suggests to me that the first command binds an attribute but that the second command does not disable it. This is fine if, for example, you haven't destroyed the attribute, but if you destroy it, then the second command expects it to be available even if it's not used.

require('regl')({
  onDone: (err, regl) => {
    if (err) return console.error(err);

    var vertexBuffer = regl.buffer([-1, -1, 0, 1, -1, 0, 0, 1, 0]);
    var colorBuffer = regl.buffer([1, 0, 0, 0, 1, 0, 0, 0, 1]);

    var commandWithTwoAttributes = regl({
      vert: `
        precision mediump float;
        attribute vec3 aPosition;
        attribute vec3 aColor;
        varying vec3 vColor;
        void main () {
          vColor = aColor;
          gl_Position = vec4(aPosition, 1);
        }
      `,
      frag: `
        precision mediump float;
        varying vec3 vColor;
        void main () {
          gl_FragColor = vec4(vColor, 1);
        }
      `,
      attributes: {
        aPosition: vertexBuffer,
        aColor: colorBuffer
      },  
      count: 3
    }); 

    var commandWithOneAttribute = regl({
      vert: `
        precision mediump float;
        attribute vec3 aPosition;
        void main () {
          gl_Position = vec4(aPosition, 1);
        }
      `,
      frag: `
        precision mediump float;
        void main () {
          gl_FragColor = vec4(1, 0, 0, 1);
        }
      `,
      attributes: {
        aPosition: vertexBuffer,
      },  
      count: 3
    }); 

    console.log('invoke command with two attributes');
    commandWithTwoAttributes();

    setTimeout(() => {
      console.log('destroy color buffer');
      colorBuffer.destroy();

      setTimeout(() => {
        console.log('invoke command with one attribute');
        commandWithOneAttribute();
      }, 1000);
    }, 1000);
  }
});

/cc @mikolalysenko and maybe @dy if interested (though maybe you're using your gl-utils library at the moment? 😄)

@rreusser rreusser changed the title Attributes not cleaned up properly Unused attributes not cleaned up properly May 13, 2018
@rreusser rreusser changed the title Unused attributes not cleaned up properly Unused attributes not disabled May 13, 2018
@rreusser rreusser changed the title Unused attributes not disabled Command fails if unrelated attributes are destroyed May 13, 2018
@rreusser rreusser changed the title Command fails if unrelated attributes are destroyed Command fails if unrelated buffers are destroyed May 13, 2018
@rreusser rreusser changed the title Command fails if unrelated buffers are destroyed Command fails if unrelated attribute buffers are destroyed May 13, 2018
@rreusser rreusser changed the title Command fails if unrelated attribute buffers are destroyed Command fails if buffers for unrelated attributes are destroyed May 13, 2018
@rreusser
Copy link
Member Author

Appears to be a duplicate of #413, which probably needs a publish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant