glDrawxxx attempt to access out of range vertices
Howdy guys, I've been following the tutorials on learningwebgl.com and I've run into a snag with my current project.
I am trying to render a point cloud from a text file. I can parse the file and build an array of vertices. Yet there seems to be an issue with loading the array into the buffer.
Because of this, I get an out of range error when trying to draw the scene.
My parsing code:
var splitByLine = responseText.split("\r\n");
numVerts=splitByLine.length; // Array of lines, each line represents a point
for(var j = 0; j<splitByLine.length;j++)
var tmpArray = new Array();
tmpArray = splitByLine[j].split("\t");
My init Buffer code:
vertexPosBuffer = gl.createBuffer();
My draw scene code:
External to this code is where I declare my global variables:
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
var vertexLocations = new Array();
Any help would be appreciated in figuring out the issue. When I look at the buffer with webgl inspector, it says that the array of vertex data that I am passing it, is null. Yet when I step through the code I can see that the array contains the proper data.
Re: glDrawxxx attempt to access out of range vertices
If anyone else ever has such a problem, I found that my buffer initialization function was being called before my file handler finished loading.
I fixed this by calling the buffer inside the file handler instead of in the main part of my code.