使用LWJGL3生成顶点数组时发生核心转储错误

时间:2018-07-16 20:05:50

标签: java opencl lwjgl

所以我想开始使用LWJGL3,我想做一个简单的窗口,用存储在GPU中的顶点绘制2个三角形。运行代码时,我不断收到此错误。Java已检测到致命错误

Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f92f01996ec, pid=4580, tid=0x00007f93664c4700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_171-b11) (build 1.8.0_171-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.171-b11 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [liblwjgl_opengl.so+0x446ec]  Java_org_lwjgl_opengl_GL30_nglGenVertexArrays__IJ+0xc
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

这是我的代码

 private void loop() {
    // This line is critical for LWJGL's interoperation with GLFW's
    // OpenGL context, or any context that is managed externally.
    // LWJGL detects the context that is current in the current thread,
    // creates the GLCapabilities instance and makes the OpenGL
    // bindings available for use.
    GL.createCapabilities();

    // Run the rendering loop until the user has attempted to close
    // the window or has pressed the ESCAPE key.
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer

        glBindVertexArray(vaoId);
        glEnableVertexAttribArray(0);

        glDrawArrays(GL_TRIANGLES, 0, vertexCount);
        glDisableVertexAttribArray(0);
        glBindVertexArray(0);


        glfwSwapBuffers(window); // swap the color buffers
        // Poll for window events. The key callback above will only be
        // invoked during this call.
        glfwPollEvents();

    }
}

private void initTriangle() {

    FloatBuffer vertBuf = MemoryUtil.memAllocFloat(vertices.length);
    vertBuf.put(vertices);
    vertBuf.flip();

    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);



    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertBuf, GL15.GL_STATIC_DRAW);


    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
}

我在循环之前调用InitTriangle,并且在vaoId = GL30.glGenVertexArrays()处收到错误消息。

任何可以告诉我我做错了什么或将我引向正确方向的人,我都会感激的。

1 个答案:

答案 0 :(得分:0)

在制造GLCapabilites之前我叫initTriangle