Unsigned Int in OpenGL causes "Stack around the variable 'buffer' was corrupted."


First time asking a question on here so thanks for your patience.

I'm following a tutorial to render a triangle in OpenGL. Here I am initializing a buffer as an unsigned int and using it for the 2nd parameter of glGenBuffers to store the buffer object that is generated:

unsigned int buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);

but I want to generate 2 buffers, so I replaced the second line with glGenBuffers(2, &buffer), which however throws Stack around variable 'buffer' was corrupted. I understand that it must be because unsigned int only has enough bytes for 1 buffer. So let's try using an array.

Furthermore, according to the documentation http://docs.gl/gl4/glGenBuffers, the 2nd parameter in glGenBuffers should be a pointer to an array.

Here are my attempts:

Attempt #1

    unsigned int *buffer[2];
    glGenBuffers(2, buffer[0]);
    glBindBuffer(GL_ARRAY_BUFFER, *buffer[0]);

which causes Unhandled exception at 0x00000000544DA7F3 (nvoglv64.dll) in OpenGL.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF. It throws this even when I call glGenBuffers(1, buffer[0])


Attempt #2

    unsigned int buffer[2];
    glGenBuffers(2, buffer);
    glBindBuffer(GL_ARRAY_BUFFER, *buffer);

This works. But why? The documentation requests a pointer for the 2nd param, so why does passing by value work? Shouldn't it be breaking?

I'm still fairly new to C++, so apologies if this is a basic C++ pointer issue.


0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0