WebGL:GL错误:GL_INVALID_OPERATION:glDrawElements:尝试访问属性0中超出范围的顶点

时间:2017-10-15 00:54:29

标签: javascript runtime-error webgl wireframe

我正在尝试创建一个通用圆柱线框。我一直收到这个错误:

GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0

我正在设置我的缓冲区并像这样调用DrawElements():

       // Create a buffer object
          var vertexBuffer = gl.createBuffer();
          var indexBuffer = gl.createBuffer();

          gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
          gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);

          gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
          gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexes), gl.STATIC_DRAW);

       // Draw
          gl.drawElements(gl.LINE_STRIP, indexes.length, gl.UNSIGNED_SHORT, 0);

(另外,我知道'索引'不是索引的复数。只需使用它。)

当我收到此错误时,我的索引和顶点数组如下所示:

Vertices.length: 26
Indexes.length: 60

Indexes[]: 0,12,13,1,0,1,13,14,2,1,2,14,15,3,2,3,15,16,4,3,4,16,17,5,4,5,17,18,6,5,6,18,19,7,6,7,19,20,8,7,8,20,21,9,8,9,21,22,10,9,10,22,23,11,10,11,23,24,12,11



 Vertices[]: 
-0.7149857878684998,0.7199857831001282,0.20000000298023224,
-0.7820903062820435,0.6458441019058228,0.17320507764816284,
-0.8491948246955872,0.5717024207115173,0.17320507764816284,
-0.9162993431091309,0.4975607395172119,0.17320507764816284,
-0.9834038615226746,0.4234190583229065,0.17320507764816284,
-1.0505083799362183,0.3492773771286011,0.17320507764816284,
-1.1176128387451172,0.27513569593429565,0.17320507764816284,
-1.1847172975540161,0.20099402964115143,0.17320507764816284,
-1.251821756362915,0.1268523633480072,0.17320507764816284,
-1.318926215171814,0.05271069332957268,0.17320507764816284,
-1.386030673980713,-0.021430976688861847,0.17320507764816284,
-1.4531351327896118,-0.09557265043258667,0.17320507764816284,
-1.5202395915985107,-0.1697143167257309,0.17320507764816284,
0.7600141763687134,-0.6150141954421997,0.20000000298023224,
0.6929096579551697,-0.6891558766365051,0.17320507764816284,
0.625805139541626,-0.7632975578308105,0.17320507764816284,
0.5587006211280823,-0.837439239025116,0.17320507764816284,
0.49159613251686096,-0.9115809202194214,0.17320507764816284,
0.42449164390563965,-0.9857226014137268,0.17320507764816284,
0.35738715529441833,-1.0598642826080322,0.17320507764816284,
0.290282666683197,-1.1340059041976929,0.17320507764816284,
0.2231781780719757,-1.2081475257873535,0.17320507764816284,
0.1560736894607544,-1.2822891473770142,0.17320507764816284,
0.08896919339895248,-1.3564307689666748,0.17320507764816284,
0.021864697337150574,-1.4305723905563354,0.17320507764816284,
-0.04523979872465134,-1.504714012145996,0.17320507764816284

据我所知,我不应该引用一个超出界限的顶点,所以我不确定为什么会出现这个错误。我滥用缓冲区了吗?我对WebGL还很陌生,所以任何指向正确方向的人都会非常感激。

1 个答案:

答案 0 :(得分:1)