admin管理员组

文章数量:1287684

I have a webgl page running in chrome.

Every now and then chrome will report the following error.

[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to render with no buffer attached to enabled attribute 1

I've tried to debug where the error is occurring but I cannot. I can reliably cause it to occur, but when I debug the error is reported on seemingly random lines. I suspect this is because of the asynchronous nature of gpu rendering.

Is there a good way to debug this?

I have a webgl page running in chrome.

Every now and then chrome will report the following error.

[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to render with no buffer attached to enabled attribute 1

I've tried to debug where the error is occurring but I cannot. I can reliably cause it to occur, but when I debug the error is reported on seemingly random lines. I suspect this is because of the asynchronous nature of gpu rendering.

Is there a good way to debug this?

Share Improve this question asked Feb 18, 2015 at 16:18 Cyril MacIsaacCyril MacIsaac 1601 gold badge1 silver badge10 bronze badges 3
  • try to use the gl.vertexAttrib4f(...) instead of gl.vertexAttrib1f(...). I get a similar problem here: stackoverflow./questions/28584589/… (nobody answered still). – Andrey Bushman Commented Feb 18, 2015 at 19:30
  • 1 @Bush vertexAttrib4f is setting all values of a disabled Vertex Attribute Array, used as a default value and not at all needed if you plan to actually supply those values from a buffer. It has no effect once you enable it. – Winchestro Commented Feb 18, 2015 at 19:38
  • @ScreeniusBlack I know and I expected the same for the uniform1f (for the uniform variable), but I got the problem. Look my link. – Andrey Bushman Commented Feb 18, 2015 at 20:11
Add a ment  | 

3 Answers 3

Reset to default 5

You can use a debug wrapper to wrap the WebGL context and call gl.getError after every WebGL function.

There is an example of one available on the official WebGL Wiki.

Per default WebGL doesn't tell you much about it, you have to query all the information you need yourself. Once you know how to do that, those errors will tell you all you need to debug it. The getter for your case would be

var attribLocation = 1;
gl.getVertexAttrib ( attribLocation, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING );

Which, if you query it before your draw call, will probably return null, which means you're not calling vertexAttribPointer correctly when setting up or switching buffers.

So you go to the point in your code where you set the pointers and enable the arrays and confirm that the location you just enabled with enableVertexAttribArray returns also returns null if you query the buffer at this point. Now you know if you messed up with the pointer. You know you fixed it, when the query returns the correct WebGLBuffer Object.

There are getters for all the states (WebGL is mostly about managing state), they are a bit tricky to use, but using them will greatly help you understand everything going on all the time, when you need or don't need to make calls in order to update that state and where you made mistakes.

You can look the getters and the arguments they take up in the spec

SpectorJS is a tool aimed at WebGl developers wanting to know what happens in their context. It enables capturing of all the available information from a frame. You will be able to look at your entire mands list with their associated visual states and context information.

https://github./BabylonJS/Spector.js

本文标签: javascriptdebugging webgl in chromeStack Overflow