View Full Version : glDrawArrays crashes when fed more than 703 vertices?
11-10-2003, 08:06 PM
I'm trying to learn how to effectively use vertex arrays, but I've encountered a strange problem.
Whenever I call glDrawArrays(GL_POINTS, 0, 704), my program crashes. If I reduce the latter number by one to 703, the program runs fine.
Why is this?
11-10-2003, 08:37 PM
It sounds like your vertex array only has 703 elements in it. Do you know how many vertices you are trying to draw? How are you setting up your VertexPointer?
11-11-2003, 07:20 AM
I used DrawArrays with 4 million vertices, and it didn't crash. Something else is wrong.
11-11-2003, 07:49 AM
I'm guessing Yakuza is right, your vertex array, or one of the other arrays you setup have fewer than 703 elements. Trying to use 703 in glDrawArrays is causing you to touch memory you have no business touching, and thus the crash. (Most crashes, in my experience, are from touching memory you have no business touching...) http://www.opengl.org/discussion_boards/ubb/smile.gif
Make sure you have at least 703 elements in all the gl*Pointer functions you call. For instance, with the following:
glVertexPointer(3, GL_FLOAT, 0, floatarray);
float array would need to have at least 703*3. (The first parameter, 3, says that each vertex has 3 elements, x,y,z)
Also, if you don't have a tightly packed array and are setting your stride (0 in my example), make sure that doesn't cause you to read beyond the end of the array.
[This message has been edited by Deiussum (edited 11-11-2003).]
11-11-2003, 08:28 PM
Thank you all for your replies.
I think I was overstepping my array... all by a small thing I overlooked.
It seems I was allocating an array large enough to hold an arbitrary number of 2D vertices. Since there were two values per vertex, I needed to specify in glDrawArrays to only read half as many vertices as the actual size of the array. By some weird fluke I was able to overstep the bounds of the array by quite a bit before the program would puke... I'm now able to tell my test program to draw about a million vertices worth of junk points, line segments, or whatever and it works seemingly perfectly.
Thanks again for your help. I look forward to frequenting this forum often.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.