我第一次遇到这个问题,今天之前一切都运转良好。在我看来,问题在于内存管理或类似的东西。
我将所有opengl代码压缩在一个类中,我从主窗口循环中调用它。还是一样的错误。
public class renderTest
{
public float[] vertices(int x, int y, int z)
{
float vertices[] =
{
//...
};
return vertices;
}
public final int[] indices =
{
//...
};
public Model model;
public renderTest()
{
this.model = loadToVAO(vertices(0, 0, -5), indices);
}
public void render(Model model)
{
glBindVertexArray(model.getVaoID());
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glDrawElements(GL_QUADS, model.getVertexAmount(), GL_UNSIGNED_INT, 0); // <<< FATAL ERROR HERE
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, 0); // <<< OR HERE
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindVertexArray(0);
}
public Model loadToVAO(float[] vertices, int [] indices)
{
int vaoID = create();
bindIndicesBuffer(indices);
storeDataInAttributeList(0, vertices, 3);
//storeDataInAttributeList(1, textureCoords, 2);
unbind();
return new Model(vaoID, indices.length);
}
private int create()
{
int ID = glGenVertexArrays();
glBindVertexArray(ID);
return ID;
}
private void storeDataInAttributeList(int attributeNumber, float[] data, int coordinateSize)
{
int vboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboID);
FloatBuffer buffer = storeDataInFloatBuffer(data);
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
glVertexAttribPointer(attributeNumber, coordinateSize, GL_FLOAT, false, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
private FloatBuffer storeDataInFloatBuffer(float[] data)
{
FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
buffer.put(data);
buffer.flip();
return buffer;
}
private IntBuffer storeDataInIntBuffer(int[] data)
{
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
buffer.put(data);
buffer.flip();
return buffer;
}
private void bindIndicesBuffer(int[] indices)
{
int vboID = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID);
IntBuffer buffer = storeDataInIntBuffer(indices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
}
private void unbind()
{
glBindVertexArray(0);
}
}
Java Runtime Environment检测到致命错误:
EXCEPTION_ACCESS_VIOLATION(0xc0000005)at pc = 0x0000000055cdb5c0,pid = 5200,tid = 4540
JRE版本:Java(TM)SE运行时环境(8.0_40-b26)(版本1.8.0_40-b26)
Java VM:Java HotSpot(TM)64位服务器VM(25.40-b25混合模式windows-amd64压缩oops)
有问题的框架: C [atio6axx.dll + 0x23b5c0]
无法编写核心转储。默认情况下,在Windows的客户端版本
上未启用小型转储崩溃发生在Java虚拟机之外的本机代码中。 查看有问题的框架,了解报告错误的位置。
答案 0 :(得分:0)
最后,我想通了。问题出在这两行代码中:
glEnableVertexAttribArray(1);
//...
glDisableVertexAttribArray(1);
我启用了一个不存在的VAO。愚蠢的我。