vertex VBO + color VBO with different sizes=crash?

Hi OpenGL community.

Hope you can help on this. :slight_smile:

I have two VBO:

  • one of N vertex
  • one of less that N color

On linux, it work “well”. The color is “nothing” (random value depending of the memory I suppose but it work, OpenGL can draw).

On Mac, this seems to be a problem. It segfault on glDrawElement.

My question is pretty simple for an advanced OpenGL user:

Is it normal it crash if VBOs doesn’t have a coherent size?

If so, I suppose I have to manually feed the rest of the color VBO with empty color. Am I right?

Thanks in advance! :slight_smile:

Regards,

Dorian

All of the vertex attribute arrays will need to be the same length - the length specified by glDrawElements.

Ok thanks!

So if you have a vertex VBO of 3N elements, you need a color VBO of 4N elements (I use Alpha).

Thanks for the answer! :slight_smile:

Regards,

Dorian

You’re confusing the size of the array with the number of elements of the vertex attribute.

Whatever vertex attributes you are enabling (vertex/position/normal/color), they must all have the same number of elements (number of elements != array size).

Vertex color array can have 4 components (RGBA) per vertex, whereas normals always have 3 (XYZ). So the normal array must be (numVerts3) and color array (numVerts4). The array sizes differ, but they have the same number of vertices (elements).

If the attribute arrays do not have the same number of elements, it may result in undefined behavior according to the GL specification. On most decent GL implementations, you might get zeroes (the black you describe) or garbage (essentially zero or non-zero random values as the driver/hardware is accesing memory outside where it should not be allowed). If the graphics drivers are crappy, they may crash the application as happens for you on Mac. On many platforms, this undefined behavior is generally forgiving for backwards compatibility. There are a lot of legacy games/applications out there that would otherwise be unusable.

@remdul

No no! Really! I think I understand the difference between number of elements and array size (even if I wasn’t clear). :frowning:

On most decent GL implementations, you might get […] garbage (essentially zero or non-zero random values as the driver/hardware is accesing memory outside where it should not be allowed).

This is what I have on Linux.

So I suppose I just have to garbage the color VBO and this should solve the problem.

Thanks again. :slight_smile:

PS: Very nice and interesting web site @remdul. :slight_smile: Keep the good work!