Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: glDrawArrays crashes when fed more than 703 vertices?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2003
    Posts
    2

    glDrawArrays crashes when fed more than 703 vertices?

    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?

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Fort Collins, Colorado
    Posts
    447

    Re: glDrawArrays crashes when fed more than 703 vertices?

    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?

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2003
    Location
    Bucharest, Romania
    Posts
    124

    Re: glDrawArrays crashes when fed more than 703 vertices?

    Hi,
    I used DrawArrays with 4 million vertices, and it didn't crash. Something else is wrong.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: glDrawArrays crashes when fed more than 703 vertices?

    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...)

    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).]
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2003
    Posts
    2

    Re: glDrawArrays crashes when fed more than 703 vertices?

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •