首页 > 解决方案 > lwjgl glfwCreateWindow 导致崩溃

问题描述

我正在尝试用 lwjgl 编写一个 opengl 渲染器。要打开窗口,我使用的是 glfw。但是,当我调用 glfwCreateWindow 时,它会因以下错误而崩溃:

Java 运行时环境检测到一个致命错误:

SIGSEGV (0xb) 在 pc=0x00007fff2d732924,pid=64615,tid=775

JRE 版本:Java(TM) SE Runtime Environment (14.0.2+12) (build 14.0.2+12-46) Java VM:Java HotSpot(TM) 64-Bit Server VM (14.0.2+12-46,混合模式、共享、分层、压缩 oops、g1 gc、bsd-amd64) 有问题的框架:C [HIToolbox+0x27924] _ZNK22THIThemeTextInfoFinder10GetOptionsEv+0x8

不会写入核心转储。核心转储已被禁用。要启用核心转储,请在再次启动 Java 之前尝试“ulimit -c unlimited”

包含更多信息的错误报告文件保存为:/Users/vic/eclipse-workspace/Engine/hs_err_pid64615.log

如果您想提交错误报告,请访问: https ://bugreport.java.com/bugreport/crash.jsp

这是我的代码:

package main;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;

public class Main {

    public static void main(String[] args) {
        if(!GLFW.glfwInit()) {
            System.err.println("Failed to initialize glfw");
            System.exit(-1);
        }
        
        GLFW.glfwDefaultWindowHints();
        GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
        GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
        long window = GLFW.glfwCreateWindow(640, 480, "My window", 0, 0);
        
        if(window == 0) {
            System.err.println("Failed to create window");
            System.exit(-1);
        }
        
        GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
        GLFW.glfwSetWindowPos(window, (videoMode.width() - 640) / 2, (videoMode.height() - 480) / 2);
        
        GLFW.glfwShowWindow(window);
        
        while(!GLFW.glfwWindowShouldClose(window)) {
            GLFW.glfwPollEvents();
        }
        
        GLFW.glfwTerminate();
    }

}

我正在使用mac和eclipse。

谢谢!

标签: javaopengllwjglglfw

解决方案


解决方案是将 -XstartOnFirstThread 添加到 JVM 参数中。


推荐阅读