【问题标题】:Asynchronous XLib Error after creating context in LWJGL 3 - Linux在 LWJGL 3 中创建上下文后出现异步 XLib 错误 - Linux
【发布时间】:2020-09-02 07:18:00
【问题描述】:

我正在尝试使我的 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, 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异常。 非常感谢任何可以为我指明正确方向的帮助。如果需要更多代码示例,请告诉我,我会更新我的帖子。

【问题讨论】:

  • 如果您在其他代码中的任何位置使用 AWT/Swing 窗口,那么事情中断。 LWJGL 3 和更普遍的 GLFW 窗口事件处理与 AWT/Swing 兼容。请参阅:github.com/LWJGL/lwjgl3/issues/149github.com/LWJGL/lwjgl3/issues/149#issuecomment-269078480
  • 事实上我没有在我的代码中的任何地方使用 AWT/Swing。我只在游戏崩溃时使用 JOptionPane 来显示错误消息,但在正常执行中,它们实际上都没有出现。是的,我进行了谷歌搜索并找到了该 github 链接,这对我没有帮助,这就是我决定在这里提问的原因。
  • 我现在感觉很愚蠢,但问题是我在应用程序启动时调用了 JOptionPane.showMessageDialog(String) 并且不知何故忘记提及它......只是删除它使程序工作美好的。很抱歉浪费大家的时间

标签: java opengl lwjgl glfw xlib


【解决方案1】:

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

【讨论】:

  • 所以,毕竟是因为使用了 AWT/Swing 或者更准确地说,是因为启动了 AWT 的 Event dispatcher 线程/循环,这正是 AWT 与 GLFW 不兼容的原因,因为两者都试图打架决定谁来处理窗口消息。
  • 我还发现,如果我做同样的事情,但在调用GL.createcapabilities() 之后不会造成任何问题
  • 那个命令应该没有任何作用。 GL.createCapabilities() 所做的一切基本上就是发出一堆 wgl/glX/...GetProcAddress() 调用来获取调用线程中当前 OpenGL 上下文的函数指针。
猜你喜欢
  • 1970-01-01
  • 2018-05-20
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
  • 1970-01-01
  • 1970-01-01
  • 2020-12-29
  • 1970-01-01
相关资源
最近更新 更多