GL11.glDrawArrays weirdness

Started by Mr EEK, October 11, 2005, 20:52:12

Previous topic - Next topic

Mr EEK

I'm having some trouble with GL11.glDrawArrays.

I've got two FloatBuffers containing the vertex and normal values for a very large number of triangles.  I then do

GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
GL11.glVertexPointer(3, GL11.GL_FLOAT, vertexFB);
GL11.glNormalPointer(GL11.GL_FLOAT, normalFB);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);

(where size = number of triangles * 3).

The glDrawArrays call causes the JVM to crash if (and here's the bizarre bit) size >= 558.  If size is < 558, the JVM doesn't crash (but the triangles drawn don't look at all like I expect  :cry: )

JVM crash:

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x04461274, pid=3172, tid=2616
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0-b64 mixed mode, sharing)
(etc...)


I'm on Windows-XP, GeForce6600.

Please be patient with me, I'm a n00b  :D

elias

You need to make sure the enabled arrays are large enough. Specifically:

GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); 
GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY); 
GL11.glVertexPointer(3, GL11.GL_FLOAT, vertexFB); 
GL11.glNormalPointer(GL11.GL_FLOAT, normalFB);
if (vertexFB.remaining() < size*3 || normalFB.remaining() < size*3)
    throw new RuntimeException("vertexFB and/or normalFB is not large enough!");
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);


- elias

Mr EEK

Thanks for your reply elias.

I was thinking along the same lines (i.e. a memory error from incorrectly sized/positioned buffers) - I have called rewind on my buffers and I checked their capacity and limit, and they looked OK.

I'll try again when I get home tonight, using the "remaining" method you mention.

[I made a mistake in my original post; size = number of triangles * 3 * 3 (3 vertices, 3 floats per vertex).]

elias

That's wrong, glDrawArrays expects the size in terms of vertices, so it should only be num_triangles*3.

- elias

Mr EEK

Ah, OK, thanks elias.  I'll have another go at it tonight and let you know how I get on.

Mr EEK

Elias,

I found out what I was doing wrong:

GL11.glVertexPointer(3, GL11.GL_FLOAT, vertexFB);
GL11.glNormalPointer(GL11.GL_FLOAT, normalFB);

should have been

GL11.glVertexPointer(3, 0, vertexFB);
GL11.glNormalPointer(0, normalFB);

I had put GL11.GL_FLOAT as the stride  :oops: .  Of course, the int value of GL11.GL_FLOAT is obviously more than zero so I was striding through my data too quickly and my Buffers were therefore too short.  (I am working from the red book; the example code has GL_FLOAT as the second argument and I copied, forgetting that LWJGL would already know this from the Buffer type.)

Thanks for your help, sorry it turned out to be such a daft error after all that!

Fool Running

I've done that many times  :lol:
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D