PDA

View Full Version : c++ opengl nvoglv32.dll error



zee2200
05-15-2016, 04:29 PM
have a sprite class to handle initializing a sprite and drawing it but i keep getting this error "Exception thrown at 0x69B3C760 (nvoglv32.dll) in Flora.exe: 0xC0000005: Access violation reading location 0x00000000." I'm not exactly sure what is causing this. Here's the source code for it


void Sprite::init(int vertNum, float r, Shape shape) {
_vertNum = vertNum;
if (_vboID = 0) {
glGenBuffers(1, &_vboID);
}
std::vector<Vertex> vertexData(vertNum);
if (shape == Shape::CIRCLE) {
for (int i = 0; i < vertNum; i++) {
vertexData[i].setPosition(r*cos(i), r*sin(i));
}
}
for (int i = 0; i < _vertNum; i++) {
vertexData[i].setColor(1, 1, 1, 1);
}
glBindBuffer(GL_VERTEX_ARRAY, _vboID);
glBufferData(GL_VERTEX_ARRAY, sizeof(vertexData), vertexData.data(), GL_DYNAMIC_DRAW);
glBindBuffer(GL_VERTEX_ARRAY, 0);
}

void Sprite::draw() {
//bind buffer array
glBindBuffer(GL_ARRAY_BUFFER, _vboID);

//use first vertex attrib array
glEnableVertexAttribArray(0);

//pointer to vertices location
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
//pointer to vertices color
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, color));

//Draw the 6 vertices to the screen
glDrawArrays(GL_POLYGON, 0, _vertNum);

//Disable the vertex attrib array. This is not optional.
glDisableVertexAttribArray(0);

//Unbind the VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
}

Spoops
05-15-2016, 05:41 PM
if (_vboID = 0) {
glGenBuffers(1, &_vboID);
}


You mean == instead of =
In your case the condition will never be satisfied and you will operate on a buffer that does not exist.

zee2200
05-15-2016, 06:38 PM
You mean == instead of =
In your case the condition will never be satisfied and you will operate on a buffer that does not exist.

oh wow i can't believe i missed that, how ever now it's giving me a different error. The message it gives is "Exception thrown at 0x00BBFDB5 in Flora.exe: 0xC0000005: Access violation reading location 0x00000000.". im not sure what these mean are they error codes? if so where can i find what they mean? sorry for the newbie questions im very new to c++ and opengl

mhagain
05-16-2016, 01:31 AM
oh wow i can't believe i missed that, how ever now it's giving me a different error. The message it gives is "Exception thrown at 0x00BBFDB5 in Flora.exe: 0xC0000005: Access violation reading location 0x00000000.". im not sure what these mean are they error codes? if so where can i find what they mean? sorry for the newbie questions im very new to c++ and opengl

They mean that you have a NULL pointer somewhere.

However, I suggest you fix this first:
glBindBuffer(GL_VERTEX_ARRAY, _vboID);
glBufferData(GL_VERTEX_ARRAY, sizeof(vertexData), vertexData.data(), GL_DYNAMIC_DRAW);
glBindBuffer(GL_VERTEX_ARRAY, 0);
Should be GL_ARRAY_BUFFER, not GL_VERTEX_ARRAY.

Then you can move on to the fact that you're drawing from attrib arrays 0 and 1 but only enabling attrib array 0.

zee2200
05-16-2016, 06:00 AM
They mean that you have a NULL pointer somewhere.

However, I suggest you fix this first:
glBindBuffer(GL_VERTEX_ARRAY, _vboID);
glBufferData(GL_VERTEX_ARRAY, sizeof(vertexData), vertexData.data(), GL_DYNAMIC_DRAW);
glBindBuffer(GL_VERTEX_ARRAY, 0);
Should be GL_ARRAY_BUFFER, not GL_VERTEX_ARRAY.

Then you can move on to the fact that you're drawing from attrib arrays 0 and 1 but only enabling attrib array 0.

Ah ok I was following some tutorial and looked and I guess the source code he offered wasn't 100% right. anyways thank you so much for your help!