【问题标题】:LWJGL: Opening window causes program to crashLWJGL:打开窗口导致程序崩溃
【发布时间】:2016-01-10 06:48:15
【问题描述】:

我正在尝试用 Java / LWJGL 制作一个简单的游戏。我正在关注在 Windows 上制作的教程,并且我使用的是 Mac。我复制了他为字符打开一个窗口字符的代码,程序立即崩溃,给我一个很长很奇怪的错误,可能与指针有关(我实际上不知道)。下面是用于创建窗口的行,我在属性中定义了宽度和高度:

 window = glfwCreateWindow(width, height, "Flappy Bird", NULL, NULL);

当我在我的 mac 上运行它时,它给了我这个错误:

2015-10-12 13:18:38.475 java[496:31875] *** Assertion failure in + [NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-1154/Misc.subproj/NSUndoManager.m:340
2015-10-12 13:18:38.476 java[496:31875] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2015-10-12 13:18:38.476 java[496:31875] (
0   CoreFoundation                      0x00007fff98c3003c __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x00007fff9620a76e objc_exception_throw + 43
2   CoreFoundation                      0x00007fff98c2fe1a +[NSException raise:format:arguments:] + 106
3   Foundation                          0x00007fff99f6199b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4   Foundation                          0x00007fff99ee364f +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 156
5   AppKit                              0x00007fff96ecbb95 -[NSApplication run] + 756
6   libglfw.dylib                       0x000000010d597974 initializeAppKit + 1332
7   libglfw.dylib                       0x000000010d597035 _glfwPlatformCreateWindow + 37
8   libglfw.dylib                       0x000000010d59397b glfwCreateWindow + 443
9   ???                                 0x0000000104411eee 0x0 + 4366343918
10  ???                                 0x0000000104406929 0x0 + 4366297385
11  ???                                 0x0000000104406929 0x0 + 4366297385
12  ???                                 0x0000000104406929 0x0 + 4366297385
13  ???                                 0x000000010440685a 0x0 + 4366297178
14  ???                                 0x0000000104406d34 0x0 + 4366298420
)
2015-10-12 13:18:38.477 java[496:31875] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-1154/Misc.subproj/NSUndoManager.m:340
2015-10-12 13:18:38.477 java[496:31875] An uncaught exception was raised
2015-10-12 13:18:38.477 java[496:31875] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2015-10-12 13:18:38.477 java[496:31875] (
0   CoreFoundation                      0x00007fff98c3003c __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x00007fff9620a76e objc_exception_throw + 43
2   CoreFoundation                      0x00007fff98c2fe1a +[NSException raise:format:arguments:] + 106
3   Foundation                          0x00007fff99f6199b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4   Foundation                          0x00007fff99ee364f +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 156
5   AppKit                              0x00007fff96ecbc41 -[NSApplication run] + 928
6   libglfw.dylib                       0x000000010d597974 initializeAppKit + 1332
7   libglfw.dylib                       0x000000010d597035 _glfwPlatformCreateWindow + 37
8   libglfw.dylib                       0x000000010d59397b glfwCreateWindow + 443
9   ???                                 0x0000000104411eee 0x0 + 4366343918
10  ???                                 0x0000000104406929 0x0 + 4366297385
11  ???                                 0x0000000104406929 0x0 + 4366297385
12  ???                                 0x0000000104406929 0x0 + 4366297385
13  ???                                 0x000000010440685a 0x0 + 4366297178
14  ???                                 0x0000000104406d34 0x0 + 4366298420
)
2015-10-12 13:18:38.478 java[496:31875] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
0   CoreFoundation                      0x00007fff98c3003c __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x00007fff9620a76e objc_exception_throw + 43
2   CoreFoundation                      0x00007fff98c2fe1a +[NSException raise:format:arguments:] + 106
3   Foundation                          0x00007fff99f6199b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4   Foundation                          0x00007fff99ee364f +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 156
5   AppKit                              0x00007fff96ecbc41 -[NSApplication run] + 928
6   libglfw.dylib                       0x000000010d597974 initializeAppKit + 1332
7   libglfw.dylib                       0x000000010d597035 _glfwPlatformCreateWindow + 37
8   libglfw.dylib                       0x000000010d59397b glfwCreateWindow + 443
9   ???                                 0x0000000104411eee 0x0 + 4366343918
10  ???                                 0x0000000104406929 0x0 + 4366297385
11  ???                                 0x0000000104406929 0x0 + 4366297385
12  ???                                 0x0000000104406929 0x0 + 4366297385
13  ???                                 0x000000010440685a 0x0 + 4366297178
14  ???                                 0x0000000104406d34 0x0 + 4366298420
)
libc++abi.dylib: terminating with uncaught exception of type NSException

还会弹出一个窗口,上面写着“java 在使用 libglfw.dylib 插件时意外退出。”

是我安装 LWJGL 错误还是我的代码有缺陷?感谢您的帮助!

<terminated>

【问题讨论】:

  • 您不应忽略所有异常。在您现在只需返回的任何地方抛出异常或打印消息。您还应该使用glfwSetErrorCallback 设置错误回调并使用-Dorg.lwjgl.util.Debug=true 运行您的程序。

标签: java opengl lwjgl


【解决方案1】:

确保使用 jvm 标志 -XstartOnFirstThread 运行应用程序。尽管这似乎是专门针对 OSX 的。 See this SO Answer what this argument means

【讨论】:

  • 这节省了我的时间,而且效果很好。
【解决方案2】:

如果您使用的是 LWJGL 3,我建议您按照 Oskar 的视频教程设置项目和显示。

Workspace setting

Display tutorial

并尝试在 glfwCreateWindow 调用中使用 MemoryUtil.NULL 而不是标准的 null

【讨论】:

  • MemoryUtil.NULL 很长,而 null 是一个对象,所以你不能“用它来代替”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-03
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多