# glMultiDrawArrays strange behavior

Here is the main parts of the code. It only draws the green and yellow discs I am using MSYS2 under Win 10 and trying to draw a bull’seye with 5 discs

``````void drawDisc(float R, float X, float Y, float Z, float red, float green, float blue,int ord)
{
float t;
int i;

vertices[(ord-1)*(N+2)*3]=X;
vertices[(ord-1)*(N+2)*3+1]=Y;
vertices[(ord-1)*(N+2)*3+2]=Z;
colors[(ord-1)*(N+2)*3]=red;
colors[(ord-1)*(N+2)*3+1]=green;
colors[(ord-1)*(N+2)*3+2]=blue;
for (i = 0; i <= N; ++i)
{
t = 2.0 * PI * i / N;

vertices[(ord-1)*(N+2)*3+3*(i+1)]=X+cos(t)*R;
vertices[(ord-1)*(N+2)*3+3*(i+1)+1]=Y+sin(t)*R;
vertices[(ord-1)*(N+2)*3+3*(i+1)+2]=Z;
colors[(ord-1)*(N+2)*3+3*(i+1)]=red;
colors[(ord-1)*(N+2)*3+3*(i+1)+1]=green;
colors[(ord-1)*(N+2)*3+3*(i+1)+2]=blue;
}
first[ord-1]=(ord-1)*(N+2)*3;
countVertices[ord-1]=(N+2);
}
``````

It gets called as:

``````	drawDisc(40.0, 50.0, 50.0, 0.0, 0.0, 1.0, 0.0, 1);
drawDisc(32.0, 50.0, 50.0, 0.2, 1.0, 0.0, 0.0, 2);
drawDisc(24.0, 50.0, 50.0, 0.4, 0.0, 0.0, 1.0, 3);
drawDisc(16.0, 50.0, 50.0, 0.6, 1.0, 1.0, 0.0, 4);
drawDisc(8.0, 50.0, 50.0, 0.8, 1.0, 0.0, 1.0, 5);
glMultiDrawArrays(GL_TRIANGLE_FAN, &first[0], &countVertices[0], 5);
glFlush();
``````

I spent hours debugging and printing out every possible value I can think of, but to no avail. Any hint to what might be the issue is appreciated…

The `*3` shouldn’t be there. The index refers to vertices, not components (floats). That’s causing you to advance by three rings at a time rather than 1, hence you’re only getting the first and fourth rings (green and yellow).

Thanks a lot that was the problem. But shouldn’t I had gotten a segmentation fault like run-time memory violation. Never would have thought of it, that was extremely helpful especially that the documentation is very terse and concise and I searched the internet for an example but could not find one.

It depends. If the vertex data is stored in a buffer object, the implementation knows the size of the buffer and can check for overruns. If it’s stored in client memory, you’ll only get a segmentation fault if no memory is mapped to the space beyond the end of the array. Otherwise, it will just end up reading whatever is in that memory (if it’s all zeros or some other repeating pattern, you’ll end up with zero-area triangles where all vertices have the same position).