Error on glDrawElements using IBO

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Error on glDrawElements using IBO

ericg
I'm trying render a couple of triangles using an IBO but when I call glDrawelements I get a fatal error in the JRE.  I'm wondering if it has something to with a mismatch between uint and int?

Has anyone experienced this before?
A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000005ca0e6c0, pid=5196, tid=5112

JRE version: 6.0_21-b07 Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0-b17 mixed mode windows-amd64 ) Problematic frame: C [nvoglv64.DLL+0xb7e6c0]

An error report file with more information is saved as: C:\&&&&&&&&&&&&&&&&&&\hs_err_pid5196.log

If you would like to submit a bug report, please visit: http://java.sun.com/webapps/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

float[] colors = {    1.0f, 0.0f, 0.0f,
      0.0f, 1.0f, 0.0f,
       0.0f, 0.0f, 1.0f,
       5.0f, 0.0f, 0.0f};

float[] dataBuffer = {-1,-1,1,
      1,-1, 1,
      1,1,1,
      -1,1,1};

int[] idxBuffer = {0,1,2,2,3,0};

//**** INIT ROUTINE *****
  vboHandles = new int[3];
  gl.glGenBuffers(3, vboHandles, 0);

  //populate the position buffer
  FloatBuffer fbData = Buffers.newDirectFloatBuffer(dataBuffer);
  gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboHandles[0]); //the vertex data
  gl.glBufferData(GL4.GL_ARRAY_BUFFER, fbData.capacity() * 4,
          fbData, GL4.GL_STATIC_DRAW);

  //populate the color buffer
  FloatBuffer fbColors = Buffers.newDirectFloatBuffer(colors);
  gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboHandles[1]);
  gl.glBufferData(GL4.GL_ARRAY_BUFFER, fbColors.capacity() * (Float.SIZE / Byte.SIZE),
          fbColors, GL4.GL_STATIC_DRAW);

//index buffer IBO Vertex
  IntBuffer dtaIndc = Buffers.newDirectIntBuffer(idxBuffer);
  gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, vboHandles[2]);
  gl.glBufferData(GL4.GL_ELEMENT_ARRAY_BUFFER, dtaIndc.capacity() * (Integer.SIZE / Byte.SIZE),
          dtaIndc, GL4.GL_STATIC_DRAW);

  //set vertex array index
  IntBuffer intBuffer = BufferUtil.newIntBuffer(1);
  gl.glGenVertexArrays(1, intBuffer);
  iVao = intBuffer.get(0);
  gl.glBindVertexArray(iVao);

  gl.glEnableVertexAttribArray(0);
  gl.glEnableVertexAttribArray(1);

  // Select the VBO, GPU memory data, to use for colors
  gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboHandles[COLOR_IDX]);
  gl.glVertexAttribPointer(0, 3, GL4.GL_FLOAT, false, 0, 0);

  gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboHandles[VERTICES_IDX]); //the vertex data
  // Associate Vertex attribute 1 with the last bound VBO
  gl.glVertexAttribPointer(1,3,GL4.GL_FLOAT, false,  0, 0 );



//***************The render routine*****************
gl.glBindVertexArray(iVao);

//Crash here...
gl.glDrawElements(
       GL4.GL_TRIANGLES,    
       idxBuffer.length,    
       GL4.GL_UNSIGNED_INT,  
       0          
);
Reply | Threaded
Open this post in threaded view
|

Re: Error on glDrawElements using IBO

jmaasing
I usually crash the driver when I have some mismatch in buffer sizes or tell GL to draw more elements than my buffers hold but I can't spot any such mistake in your code. Maybe you forgot to glEnableVertexAttribArray before rendering?
Reply | Threaded
Open this post in threaded view
|

Re: Error on glDrawElements using IBO

ericg
Hmm, I did not call glEnableVertexAttribArray for the IBO - only for the vertex and color buffers.  I wonder if that was it?  I'll test it out tonight.  Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Error on glDrawElements using IBO

ericg
I was missing the call to bind the elements array...
gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, vboHandles[2]);