创建 lwjgl 3 macOS 问题 windows
lwjgl 3 macOS issue with creating windows
我创建了一些代码来使用 lwjgl3,并且 运行 遇到了 macOS 绑定的问题,因为我正在处理 mac。
问题是我似乎无法让我的程序创建任何 windows。我肯定知道这一点,因为程序就在那时停止了。没有错误。
代码卡住的行是:
long window = glfwCreateWindow(300, 300, "Hello World!", MemoryUtil.NULL, MemoryUtil.NULL);
因为我是在 IntelliJ 上开发的,每当我断开进程时,它就会崩溃:
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: EXC_I386_GPFLT
Exception Note: EXC_CORPSE_NOTIFY
我觉得这不是问题所在,因为我尝试 运行ning 另一个依赖于 lwjgl3 的代码,它也卡在了创建 window.
的部分
我知道代码卡在了创建 window 的部分,因为我在每一行都放了打印语句。
我真的希望这不是 macOS Big Sur 或 mac book pro 2015 型号的兼容性问题。
while glfwInit()
return true
, 当我 运行 System.out.println(glGetString(GL_VERSION) );
, 我得到这个错误 Fatal error: Thread[main,5,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.
这是我用于测试的完整代码:
public static void main(String[] args) throws Exception{
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// Should be true for macOS, according to GLFW docs, to get core profile.
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// According to Apple docs, non-core profiles are limited to version 2.1.
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create the window
long window = glfwCreateWindow(300, 300, "Hello World!", MemoryUtil.NULL, MemoryUtil.NULL);
//glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
System.out.println('0');
glfwDestroyWindow(window);
}
我用谷歌搜索了很多次:
似乎找不到相关的答案。一个人建议 macOS 有一个隐藏的弹出窗口,必须关闭才能分配 window,但我做了一切来禁用它(因为我找不到它)并且还是什么都没发生。我认为 GL_VERSION
表示 openGL 如何绑定到 Java.
的问题
[编辑]
通过传入 JVM 选项 -XstartOnFirstThread
.
确保应用程序在主线程上 运行ning
[EDIT2]
离开项目几个小时,回来重新运行。
我在顶部添加了一行:
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
createWindow(...)
函数开始工作了,这很奇怪,我不知道为什么。如果我删除该行,它也会开始工作,所以如果有人知道发生了什么,请告诉我。
我没有回答这个问题,因为我仍然不知道问题的原因,我只是很幸运,它自行修复了。
[EDIT3]
我在intellij上强行重建了整个项目,它又停止工作了。我真的很困惑为什么它在两者之间工作
我在 gradle.properties 上有 -XstartOnFirstThread。尝试在您当前拥有的 运行 配置的 jvmargs 中设置它。这对我来说已经解决了
我创建了一些代码来使用 lwjgl3,并且 运行 遇到了 macOS 绑定的问题,因为我正在处理 mac。
问题是我似乎无法让我的程序创建任何 windows。我肯定知道这一点,因为程序就在那时停止了。没有错误。
代码卡住的行是:
long window = glfwCreateWindow(300, 300, "Hello World!", MemoryUtil.NULL, MemoryUtil.NULL);
因为我是在 IntelliJ 上开发的,每当我断开进程时,它就会崩溃:
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: EXC_I386_GPFLT
Exception Note: EXC_CORPSE_NOTIFY
我觉得这不是问题所在,因为我尝试 运行ning 另一个依赖于 lwjgl3 的代码,它也卡在了创建 window.
的部分我知道代码卡在了创建 window 的部分,因为我在每一行都放了打印语句。
我真的希望这不是 macOS Big Sur 或 mac book pro 2015 型号的兼容性问题。
while glfwInit()
return true
, 当我 运行 System.out.println(glGetString(GL_VERSION) );
, 我得到这个错误 Fatal error: Thread[main,5,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.
这是我用于测试的完整代码:
public static void main(String[] args) throws Exception{
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// Should be true for macOS, according to GLFW docs, to get core profile.
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// According to Apple docs, non-core profiles are limited to version 2.1.
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create the window
long window = glfwCreateWindow(300, 300, "Hello World!", MemoryUtil.NULL, MemoryUtil.NULL);
//glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
System.out.println('0');
glfwDestroyWindow(window);
}
我用谷歌搜索了很多次:
似乎找不到相关的答案。一个人建议 macOS 有一个隐藏的弹出窗口,必须关闭才能分配 window,但我做了一切来禁用它(因为我找不到它)并且还是什么都没发生。我认为 GL_VERSION
表示 openGL 如何绑定到 Java.
[编辑]
通过传入 JVM 选项 -XstartOnFirstThread
.
[EDIT2]
离开项目几个小时,回来重新运行。 我在顶部添加了一行:
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
createWindow(...)
函数开始工作了,这很奇怪,我不知道为什么。如果我删除该行,它也会开始工作,所以如果有人知道发生了什么,请告诉我。
我没有回答这个问题,因为我仍然不知道问题的原因,我只是很幸运,它自行修复了。
[EDIT3]
我在intellij上强行重建了整个项目,它又停止工作了。我真的很困惑为什么它在两者之间工作
我在 gradle.properties 上有 -XstartOnFirstThread。尝试在您当前拥有的 运行 配置的 jvmargs 中设置它。这对我来说已经解决了