glDrawArrays访问冲突 [英] glDrawArrays Access Violation
本文介绍了glDrawArrays访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试遵循[this] [1]简单教程,但是到达"glDrawArrays"时出现以下错误:
I am trying to follow [this][1] simple tutorial, but I am getting the following error upon reaching 'glDrawArrays':
openGLTest.exe中0x03D7598E(nvoglv32.dll)处未处理的异常:0xC0000005:访问冲突读取位置0x00000000.
Unhandled exception at 0x03D7598E (nvoglv32.dll) in openGLTest.exe: 0xC0000005: Access violation reading location 0x00000000.
void createMesh(void) {
float* vertices = new float[18];// Amount of vertices
vertices[0] = -0.5; vertices[1] = -0.5; vertices[2] = 0.0; // Bottom left corner
vertices[3] = -0.5; vertices[4] = 0.5; vertices[5] = 0.0; // Top left corner
vertices[6] = 0.5; vertices[7] = 0.5; vertices[8] = 0.0; // Top Right corner
vertices[9] = 0.5; vertices[10] = -0.5; vertices[11] = 0.0; // Bottom right corner
vertices[12] = -0.5; vertices[13] = -0.5; vertices[14] = 0.0; // Bottom left corner
vertices[15] = 0.5; vertices[16] = 0.5; vertices[17] = 0.0; // Top Right corner
glGenVertexArrays(1, &vaoID[0]); // Create our Vertex Array Object
glBindVertexArray(vaoID[0]); // Bind our Vertex Array Object so we can use it
glGenBuffers(1, vboID); // Generate our Vertex Buffer Object
glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); // Bind our Vertex Buffer Object
glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), vertices, GL_STATIC_DRAW); // Set the size and data of our VBO and set it to STATIC_DRAW
glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Set up our vertex attributes pointer
glEnableVertexAttribArray(0); // Disable our Vertex Array Object
glBindVertexArray(0); // Disable our Vertex Buffer Object
delete[] vertices; // Delete our vertices from memory
glBindVertexArray(vaoID[0]); // Bind our Vertex Array Object
glDrawArrays(GL_TRIANGLES, 0, 6); // Draw our square
glBindVertexArray(0); // Unbind our Vertex Array Object
}
由于本教程相同,我对导致它的原因不知所措!
I am at a loss as to what is causing it as the tutorial is the same!
推荐答案
经过大量实验,我通过将第一行更改为以下内容来解决了该问题:
After much experimentation I fixed this issue by changing the first line to:
float vertices[18];
并删除:
delete[] vertices;
这篇关于glDrawArrays访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文