Search code examples
javaopengllwjglglfw

lwjgl glfwCreateWindow causes crash


I'm trying to code an opengl renderer with lwjgl. To open the window, I'm using glfw. However, when I call glfwCreateWindow, it crashes with this error:

A fatal error has been detected by the Java Runtime Environment:

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

JRE version: 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, mixed mode, sharing, tiered, compressed oops, g1 gc, bsd-amd64) Problematic frame: C [HIToolbox+0x27924] _ZNK22THIThemeTextInfoFinder10GetOptionsEv+0x8

No core dump will be written. 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/vic/eclipse-workspace/Engine/hs_err_pid64615.log

If you would like to submit a bug report, please visit: https://bugreport.java.com/bugreport/crash.jsp

Here is my code:

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();
    }

}

I'm using mac and eclipse.

Thanks!


Solution

  • The solution is to add -XstartOnFirstThread to the JVM arguments.