CHECK THIS OUT

This problem may be trival, but I’m totally
in awe with it. Here it is…

Im using glDrawArray to draw vertex data, which works just fine, now. The data is stored in a global array, but I was getting access violations when glDrawArrays was executed, until I added another global, static array of the same type and size.
It looked like this…

static GLfloat verts[10000];
static GLfloat nothing[10000];

And no, the # of verticies was not greater that the size of the array.

Anyone know whats up with this???

Thanks.

You are writing that “the # of verticies was not greater that the size of the array,” and yet the evidence points to your exceeding the bounds of the array.

An access violation is exactly that: accessing memory you have no buisness accessing. You should not assume that it is the fault of the OS, the driver, or the little gremlins that live in your computer unless you have very hard evidence of any of the above.

I’m not suprised that what you’ve done fixes the problem. Essentially, what you’ve done to “fix” the problem is add 10000 more floats to the back end of the array. Test this out by doing the following:

assert(((&verts[0]) + 10000) == (&nothing[0]));

If that doesn’t assert, then I’ll guess that ((&verts[0]) + 10000) is very close to &nothing[0].

If those weren’t global variables, you would probably be damaging malloc’s heap-management when you write vertex values to the array.

Did you use glEnableClientState(GL_VERTEX_ARRAY) before you enabled the vertex array?

Without seeing, at a minimum, your calls to glVertexPointer() and glDrawElements(), it is impossible to say whether the implementation or your code is at fault. I have a hunch, though :slight_smile:

I agree. It sounds like an invalid parameter to glDrawArrays or some related function is being used to make it access memory beyond your vertex array.

If you don’t want to use a commercial bounds checker, simply set the contents of the last element in your huge array to something recognisable, like -9999.9, then just test to see if it has changed value BEFORE you call DrawElements().
Another additional safety measure (and only in debug) is to use a function to write into the array, and put an assert after every write to check the last element hasn’t changed. Like this…
void AddVertex(float &v)
{
myarray[mycount+0] = v[0];
myarray[mycount+1] = v[1];
myarray[mycount+2] = v[2];
mycount+=3;

if (myarray[topelement] != 9999.9)
ASSERTLIKECRAZY();
}

If you’re using x,y,z (3 * GLfloat) style vertices, remember that the array needs to be 3 times larger.

i.e.

static GLfloat vertices[30000];

or even

static GLfloat vertices[10000][3];

depending upon how you’re accessing the array.