LWJGL3.1 任何 GL11 呼叫都会导致 SIGSEGV 故障



这是错误消息:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000137304bab, pid=55750, tid=0x000000000000080b
#
# JRE version: Java(TM) SE Runtime Environment (8.0_131-b11) (build 1.8.0_131-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [liblwjgl_opengl.dylib+0xcbab]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/leobattle/Desktop/Programming/Java/Minecraft Modding/GLGame/GLGame/hs_err_pid55750.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

我使用的是macOS 10.12并使用Java 8。

为什么会导致段错误,我该如何解决?

法典:

while (GLFW.glfwWindowShouldClose(window) != true) { 
GLFW.glfwPollEvents(); 
GL11.glClearColor(0f, 0f, 0f, 0f); 
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); 
GL11.glBegin(GL11.GL_QUADS); 
GL11.glVertex2f(-0.5f, 0.5f); 
GL11.glVertex2f(0.5f, 0.5f); 
GL11.glVertex2f(0.5f, -0.5f); 
GL11.glVertex2f(-0.5f, -0.5f); 
GL11.glEnd(); 
GLFW.glfwSwapBuffers(window);
} 

> 哎呀。解决!我忘了添加 GL.createCapabilities((;

我看到你已经在那里回答了你的问题,但我对 GL.createCapabilities(( 到底是做什么有了更多的了解。

一旦你用GLFW的glfwMakeContextCurrent((创建了你的上下文,我们只有一个你的窗口的上下文,但仍然缺少一些东西。

GL.createCapabilities(( 做了 3 件事:加载本机库,创建 GLCapability 的实例(您可以使用它来检查有关上下文的很多事情,例如兼容扩展(,并创建一些线程来管理所述 GLCapability。

(虽然我没有测试过,但我认为 GL.create(( 也会解决你的问题。

显然,您遇到的问题是缺少库,这就是给您带来错误的原因。没关系,我也遇到了同样的错误。只需确保在创建上下文(并且是当前(之后但在任何 OpenGL 调用之前调用 GL.createCapabilities((。

您可以在此处阅读更多内容:https://javadoc.lwjgl.org/org/lwjgl/opengl/GL.html

最新更新