在LWJGL 3中创建上下文后的异步XLib错误 – Linux

huangapple go评论81阅读模式
英文:

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

这是程序的设置例程:

// 初始化lwjgl
loadLibrary();

// 创建glfw窗口
System.out.println("Initializing window...");
window = new Window();

// 这部分与问题无关且不会引起任何问题
System.out.println("Initializing camera...");
camera = new Camera(window.getWidth(), window.getHeight());

// 错误发生在这里
System.out.println("Creating context...");
// "Creating context..." 当然会正确输出
GL.createCapabilities();
/*在调用此函数之后,程序只会在在显示X错误之前的0.5-1秒内保持打开状态
并且在此期间会正常进行初始化操作,确认该错误是异步的*/

窗口初始化的代码(为了更好的可读性,我只会包含相关部分,而不是整个类):

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

        // 在调用GL.createcapabilities()之前,这是必要的,否则程序会崩溃
	glfwMakeContextCurrent(window);
	
	destroyed = false;
}

我真的不知道这是由什么引起的(也因为,我再次强调,这完全相同的代码在Windows上运行得非常好),而且我没有办法捕获此错误并阻止它中止执行,因为这不是Java异常。非常感谢任何能够指导我正确方向的帮助。如果需要更多的代码示例,请告诉我,我会更新我的帖子。

英文:

I am trying to make my java program cross platform which is why i tested it on linux and the results are pretty bad. Basically, after fixing some bugs and getting the native libraries to load correctly, i am greeted by this error message as the program quits after a second or less:

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

This is the program setup routine:

//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*/

The code for window initialization (i will only include relevant parts and not the whole class for better readability):

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

I really have no idea what this is caused by (also because, i repeat, this exact same code works perfectly fine on windows), also i have no way to catch this error and preventing it from aborting execution, as it is not a java exception.
Any help that can point me in the right direction is highly appreciated. If more code samples are needed, just let me know and i'll update my post.

答案1

得分: 0

问题原来不在我在问题中发布的代码之内。显然,调用 JOptionPane.showMessageDialog(String) 就足以触发这个 X 错误... 是我自己的问题。

英文:

The problem turned out to be outside of the code i posted in my question. Apparently calling JOptionPane.showMessageDialog(String) is enough to trigger this X error... my bad

huangapple
  • 本文由 发表于 2020年9月2日 15:18:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63700553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定