"Fatal Error" Using GL_COLOR_ARRAY with VBO

Started by MattholomewCup, October 08, 2013, 23:17:52

Previous topic - Next topic

MattholomewCup

Hey again,

So I'm trying to follow this tutorial for simple 3D models: http://www.java-gaming.org/topics/lwjgl-tutorial-series-introduction-to-3d/30712/view.html

I've modified it slightly, but only in such a way as to split it up into new classes and objects to fit the structure of my project, functionally it acts exactly the same and has most of the rendering code lifted line-for-line.

However, when I run it, I get the following error:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f9b1167dee6, pid=3442, tid=140303995508480
#
# JRE version: 7.0_25-b30
# Java VM: OpenJDK 64-Bit Server VM (23.7-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libc.so.6+0x150ee6]  __nss_hosts_lookup+0x187e6
#


There's a logfile with more, if posting it would help, but it looks like it's mostly low-level memory stuff which scares me for now.

I've narrowed it down to this section of code:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);	
glVertexPointer(3, GL_FLOAT, 0, 0);

glBindBuffer(GL_ARRAY_BUFFER, vboColorID);	
glVertexPointer(3, GL_FLOAT, 0, 0l);

glDrawArrays(GL_TRIANGLES,0,12);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);


In particular, going through the debugger step by step, I can see that it breaks on glDrawArrays(). Now the funny thing is that if I comment out 'glEnableClientState(GL_COLOR_ARRAY);' and the corresponding glDisableClientState() then it works fine (without the color, of course). I'd like to try getting the color working on this and move on, does anyone have any ideas? If I can provide more code then let me know; as I said, much of it is lifted from the source of that tutorial (he includes source in a link at the end).

EDIT: Oh, I would also like to add that when I leave this block of code uncommented:
glBindBuffer(GL_ARRAY_BUFFER, vboColorID);	
glVertexPointer(3, GL_FLOAT, 0, 0l);
I can see that the position of my tetrahedron is moved to the upper-right corner, rather than the center as it was. That might be a clue as to what's off.

Fool Running

If memory serves, I think
glBindBuffer(GL_ARRAY_BUFFER, vboColorID);	
glVertexPointer(3, GL_FLOAT, 0, 0l);

should be
glBindBuffer(GL_ARRAY_BUFFER, vboColorID);	
glColorPointer(3, GL_FLOAT, 0, 0l);

or something like that.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

quew8

I second the above, but I don't see any reason why your offset should be 01, rather than 0. That parameter is the byte offset into the bound buffer where your colour data starts. I'm guessing there's nothing else in that buffer so the offset should be 0.

Whenever you get that error, it means that you have tried to access a location in memory that you shouldn't be. You can't do this in pure Java so it means that the problem is in OpenGL. Really the only time this happens is when the parameters you give glXXXPointer() are wrong, so just check over them.

Fool Running

Quote from: quew8 on October 09, 2013, 19:37:40
I second the above, but I don't see any reason why your offset should be 01, rather than 0. That parameter is the byte offset into the bound buffer where your colour data starts. I'm guessing there's nothing else in that buffer so the offset should be 0.
The 01 is actually a 0L (i.e. a long zero). I stared at that hard before I compared a lowercase L to a one and realized that.  :P
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

quew8

Nice spot, I was just wondering who would put a "01" rather than just "0."

MattholomewCup

Oh my god I am so dumb. Yep, that's exactly it. This is the kind of thing that keeps me up at night. You guys are a godsend.

Also, regarding the L / 1 thing, I figured it couldn't hurt to be explicit with my typing but I can't argue with these results - seems like it's caused rather more confusion than clarity. I'll probably just say 0 unless it causes me problems later on.

Thanks for the input!