Results 1 to 2 of 2

Thread: glDrawxxx attempt to access out of range vertices

  1. #1

    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:
    Code :
    	function handleFile(responseText)
    	{
    		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");
    			vertexLocations.push(tmpArray[0],tmpArray[1],tmpArray[2]); 
    		}
     
    	}

    My init Buffer code:
    Code :
    	function initBuffers()
    	{
    		vertexPosBuffer = gl.createBuffer();
    		gl.bindBuffer(gl.ARRAY_BUFFER,vertexPosBuffer);
    		gl.bufferData(gl.ARRAY_BUFFER,new Float32Array(vertexLocations),gl.STATIC_DRAW);
    		vertexPosBuffer.itemSize=3;
    		vertexPosBuffer.numVerts= numVerts;
    	}

    My draw scene code:
    Code :
    	function drawScene()
    	{
    	gl.viewport(0,0,gl.viewportWidth,gl.viewportHeight);
    	gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    	mat4.perspective(45,gl.viewportWidth/gl.viewportHeight,0.1,100.0,pMatrix);
    	mat4.identity(mvMatrix);
    	mat4.translate(mvMatrix,[0,0,z]);
    	mat4.rotate(mvMatrix,degToRad(xRot),[1,0,0]);
    	mat4.rotate(mvMatrix,degToRad(yRot),[0,1,0]);
    	gl.bindBuffer(gl.ARRAY_BUFFER,vertexPosBuffer)
    	gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute,vertexPosBuffer.itemSize,gl.FLOAT,false,0,0);
    	setMatrixUniforms();
    	gl.drawArrays(gl.POINTS,0, numVerts);
    	}
    External to this code is where I declare my global variables:
    var vertexLocations = new Array();
    var numVerts;
    var verts;

    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.

  2. #2

    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.

Similar Threads

  1. simple example - attempt to access out of range vertices err
    By saruniitr in forum Developers Coding:Beginner
    Replies: 2
    Last Post: 10-15-2012, 02:29 PM
  2. float4 and possible out of range?
    By sean.settle in forum OpenCL
    Replies: 4
    Last Post: 02-02-2012, 09:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •