本文介绍了Java创建BufferedImage的实例冻结程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历一些非常奇怪的事情,我根本不知道究竟是什么造成的。这是有问题的代码行:

I'm experiencing something really strange, and I don't know what's causing it at all. This is the problematic line of code:

BufferedImage out = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);

调用此函数后,所有线程都会冻结,一切都会停止。我已经尝试将它放在自己的线程和主线程中,同样的事情发生了。我正在使用LWJGL3,所以这可能是一个问题,但我不知道它是怎么回事。

Upon calling this, all threads freeze and everything stops. I've tried putting this in its own thread and the main thread, the same thing occurs. I am using LWJGL3, so that might be an issue, but I don't see how it could be.

编辑:没有LWJGL的空白项目中不会出现或者超出-XstartOnFirstThread

Does not occur in a blank project without LWJGL in or out of -XstartOnFirstThread

推荐答案

好的!我找到了解决方案。事实证明,所需要的只是以下JVM参数: -Djava.awt.headless = true 你还必须确保你没有在主线程中运行它,你必须在初始化GLFW的线程之外进行。

Ok! I found the solution. Turns out, all it takes is the following JVM argument: -Djava.awt.headless=true You also have to make sure that you aren't running it in the main thread, you have to do it outside of the thread where GLFW is initialized.

所有这些仅适用于你在Mac上运行LWJGL,Linux和Windows没有这个问题。

All of this only applies if you are running LWJGL on Mac, Linux and Windows don't have this issue.

这篇关于Java创建BufferedImage的实例冻结程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:26