【发布时间】: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/149 和 github.com/LWJGL/lwjgl3/issues/149#issuecomment-269078480
-
事实上我没有在我的代码中的任何地方使用 AWT/Swing。我只在游戏崩溃时使用 JOptionPane 来显示错误消息,但在正常执行中,它们实际上都没有出现。是的,我进行了谷歌搜索并找到了该 github 链接,这对我没有帮助,这就是我决定在这里提问的原因。
-
我现在感觉很愚蠢,但问题是我在应用程序启动时调用了 JOptionPane.showMessageDialog(String) 并且不知何故忘记提及它......只是删除它使程序工作美好的。很抱歉浪费大家的时间
标签: java opengl lwjgl glfw xlib