在 LWJGL 3 中创建上下文后出现异步 XLib 错误 - Linux

Asynchronous XLib Error after creating context in LWJGL 3 - Linux

我正在尝试让我的 java 程序跨平台,这就是我在 linux 上测试它但结果很糟糕的原因。基本上,在修复了一些错误并让本机库正确加载之后,当程序在一秒或更短时间后退出时,我收到了这条错误消息:

X Error of failed request:  RenderBadPicture (invalid Picture parameter)
  Major opcode of failed request:  139 (RENDER)
  Minor opcode of failed request:  7 (RenderFreePicture)
  Picture id in failed request: 0x4c0002b
  Serial number of failed request:  766
  Current serial number in output stream:  778

这是程序设置例程:

//Initializes lwjgl
loadLibrary();

//creates the glfw window
System.out.println("Initializing window...");
window=new Window();

//This is not relevant and does not cause any problem
System.out.println("Initializing camera...");
camera = new Camera(window.getWidth(),window.getHeight());

//This is where the error happens
System.out.println("Creating context...");
//"Creating context..." is output correctly of course
GL.createCapabilities();
/*Right after this function is called, there is only a 0,5-1 seconds window in which the program
will stay open before showing the X Error (and it continues normally in that time with the
initialization stuff, confirming that the error is asynchronous*/

window 初始化的代码(为了更好的可读性,我将只包括相关部分而不是整个 class):

public Window() {
    Dimension d = defaultD();
    int w = (int)(d.getWidth()*0.7d);
    int h = (int)(d.getHeight()*0.7d);
    width=w;
    height=h;
    createWindow(w, h);
}

public Dimension defaultD() {
    GLFWVidMode mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    int w = mode.width();
    int h = mode.height();
    return new Dimension(w,h);
}

public void createWindow(int width, int height) {
    Dimension d = defaultD();
    window = glfwCreateWindow(width, height, title, 0, 0);
    if(window==0) {
        JOptionPane.showMessageDialog(null, "Failed to initialize window");
        System.exit(1);
    }
    glfwSetWindowSizeLimits(window, width, height, width, height);
    glfwSetWindowPos(window, (int)((d.getWidth()-width)/2), (int)((d.getHeight()-height)/2));

        //this is necessary before calling GL.createcapabilities(), otherwise the program crashes
    glfwMakeContextCurrent(window);
    
    destroyed=false;
}

我真的不知道这是什么原因造成的(也是因为,我重复一遍,这段完全相同的代码在 windows 上运行得非常好),而且我也没有办法捕捉到这个错误并阻止它发生中止执行,因为它不是 java 异常。 非常感谢任何可以为我指明正确方向的帮助。如果需要更多代码示例,请告诉我,我会更新我的 post.

原来问题出在我在问题中发布的代码之外。显然调用 JOptionPane.showMessageDialog(String) 足以触发此 X 错误...我的坏