我不熟悉使用LWJGL(一般来说Java也是如此),因此,我阅读了他们关于入门的页面,他们提供了一个Hello World程序示例。我自己尝试运行它,发现它出现以下错误:<代码>2020-03-18 10:20:02.145 java[19779:1119716]***由于未捕获的异常“nSinternalinconsistenceexception”而终止应用程序,原因:“[NSUndoManager(NSInternal)\u endTopLevelGroupings]只能在主线程上安全调用
我对这意味着什么感到困惑,因为我认为除了main之外,init()方法没有在任何线程中运行,所以我添加了一行来打印它运行在哪个线程中,果然,它打印了线程[main,5,main]。
这是怎么回事,我该怎么解决?
下面是上下文的完整代码。
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
public class HelloWorld {
// The window handle
private long window;
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
loop();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable
// This should be running on main?
System.out.println(Thread.currentThread());
// Create the window -- This is where the problem is
window = glfwCreateWindow(300, 300, "Hello World!", NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
});
// Get the thread stack and push a new frame
try ( MemoryStack stack = stackPush() ) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center the window
glfwSetWindowPos(
window,
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
);
} // the stack frame is popped automatically
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);
// Make the window visible
glfwShowWindow(window);
}
private void loop() {
// This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the GLCapabilities instance and makes the OpenGL
// bindings available for use.
GL.createCapabilities();
// Set the clear color
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while ( !glfwWindowShouldClose(window) ) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glfwSwapBuffers(window); // swap the color buffers
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
}
}
public static void main(String[] args) {
new HelloWorld().run();
}
}
LWJGl3给出的示例似乎存在多个问题。组织组。
1.
2.
3个
4.
5.
提前谢了。
问题内容: 在当前的问题中(我将文件打印到Java中的物理打印机),我一直在疯狂地遍历代码,试图从所使用的每个类的javadoc中吞噬所有有用的丢失信息。 现在,我从以前的问题中抽出了很多代码,所以有相当一部分我不是自己写的。我注意到的问题是,我抓取的代码正在初始化一个对象,例如实现接口(Doc)的“SimpleDoc”并将其分配给该接口? 小代码段: 现在,据我所知,我们创建了对象。我熟悉继承,
我对glfw有一个小问题。 我的代码非常简单,我只想创建一个空窗口。 } 此代码编译,但当我运行它时,我只有一个白色窗口。窗口的标题是正确的,但里面的一切都是白色的......我尝试像那样使用glClearColor。 但是我的窗户仍然是白色的....我用的是visual studio 2015。 怎么弄个黑窗? 编辑: 忘了补充这个:glfwMakeContextCurrent(window);
以下是我的配置 java版本“1.8.0_101”java(TM)SE运行时环境(构建1.8.0_101-b13)java热点(TM)64位服务器虚拟机(构建25.101-b13,混合模式) 使用Apache http客户端v4.4调用Restful服务,服务URL具有有效的证书(SHA2) 我们使用apache http客户端调用服务。下面是代码 服务调用是间歇性失败的,有一个批处理过程在一个循
我正在尝试运行一个Spring项目。pom.xml: 结果是这样的: 2017-08-17 01:11:01.405信息9156---[restartedMain]org.ocp.TestruleemallApplication:在桌面上启动TestruleemallApplication-PL25CTR,PID 9156(C:\Users\Ilias\DesktoP\TestRuleEmall\
说明 用于初始化接口类型、协议,验证接口密钥 请求地址 http://api.dc78.cn/Api/sys_init 请求方式 GET 请求参数 参数 参数名称 必填 描述 范例 protocal 接口协议类型 否 用于声明接口使用的协议类型 mqtt type 客户端接口 否 用于说明客户端接口的类型 api 接口协议目前支持两种:mqtt、http。设置相应类型后,平台端将以此协议与客户端进