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

问题描述

我正在尝试使我的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*/

用于窗口初始化的代码(为了更好的可读性,我将仅包括相关部分,而不包括整个类):

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);
    if(window==0) {
        JOptionPane.showMessageDialog(null,"Failed to initialize window");
        System.exit(1);
    }
    glfwSetWindowSizeLimits(window,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异常。 可以向我指出正确方向的任何帮助都将受到高度赞赏。如果需要更多代码示例,请告诉我,我会更新我的帖子。

解决方法

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...