View Full Version : CHECK THIS OUT
04-17-2001, 03:41 PM
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;
static GLfloat nothing;
And no, the # of verticies was not greater that the size of the array.
Anyone know whats up with this???
04-17-2001, 04:05 PM
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) + 10000) == (¬hing));
If that doesn't assert, then I'll guess that ((&verts) + 10000) is very close to ¬hing.
If those weren't global variables, you would probably be damaging malloc's heap-management when you write vertex values to the array.
04-17-2001, 04:07 PM
Did you use glEnableClientState(GL_VERTEX_ARRAY) before you enabled the vertex array?
04-17-2001, 04:37 PM
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 :-)
04-18-2001, 04:26 AM
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.
04-23-2001, 09:03 AM
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;
myarray[mycount+1] = v;
myarray[mycount+2] = v;
if (myarray[topelement] != 9999.9)
If you're using x,y,z (3 * GLfloat) style vertices, remember that the array needs to be 3 times larger.
static GLfloat vertices;
static GLfloat vertices;
depending upon how you're accessing the array.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.