石丸です。
前回作成したプロジェクトのbuild.gradleはMacもターゲットにしているので、動作確認してみようとMacを引っ張り出してきました。
JDKのアップデート
JDKのバージョンを確認してみたらjdk1.7.0_79(Java SE 7)とびっくりするほど古かったので、macにopenjdk11をインストールを参考にOracleのOpenJDKの12へアップデート。
1
2
3
4
|
marunote:~ maru$ java --version
openjdk 12.0.2 2019-07-16
OpenJDK Runtime Environment (build 12.0.2+10)
OpenJDK 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
|
ビルドと実行
ビルドは通るけど実行したら落ちちゃう。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
2019-10-01 00:59:05.045 java[1519:18680] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1575.19/Foundation/Misc.subproj/NSUndoManager.m:361
2019-10-01 00:59:05.046 java[1519:18680] *** 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 CoreFoundation0x00007fff4706b2fd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff7173fa17 objc_exception_throw + 48
2 CoreFoundation0x00007fff47086016 +[NSException raise:format:arguments:] + 98
3 Foundation0x00007fff49325791 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 Foundation0x00007fff4925880e +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 473
5 AppKit0x00007fff445a4681 -[NSApplication run] + 916
6 libglfw.dylib 0x000000012233a9d5 libglfw.dylib + 68053
7 libglfw.dylib 0x0000000122334366 libglfw.dylib + 41830
8 ??? 0x000000010bd08990 0x0 + 4493183376
9 ??? 0x000000010bd02790 0x0 + 4493158288
)
libc++abi.dylib: terminating with uncaught exception of type NSException
|
エラーを頼りに解決方法を探し回って
LWJGL3.0.0b build 49 unhappy on OSX 10.11 #104
にたどり着く。
ウィンドウやOpenGLコンテキストを作ったりするためのGLFWをMacで実行するときは、JVMの -XstartOnFirstThread
オプションをつける必要があるとのこと。
build.gradleは次のように修正。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import org.gradle.internal.os.OperatingSystem
plugins {
id 'java'
id 'application'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
project.ext.lwjglVersion = "3.2.2"
switch (OperatingSystem.current()) {
case OperatingSystem.LINUX:
project.ext.lwjglNatives = "natives-linux"
break
case OperatingSystem.MAC_OS:
project.ext.lwjglNatives = "natives-macos"
break
case OperatingSystem.WINDOWS:
project.ext.lwjglNatives = "natives-windows"
break
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.lwjgl:lwjgl:$lwjglVersion"
implementation "org.lwjgl:lwjgl-glfw:$lwjglVersion"
implementation "org.lwjgl:lwjgl-opengl:$lwjglVersion"
runtimeOnly "org.lwjgl:lwjgl:$lwjglVersion:$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-glfw:$lwjglVersion:$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opengl:$lwjglVersion:$lwjglNatives"
}
// 実行時に-XstartOnFirstThreadをつける
applicationDefaultJvmArgs = ["-XstartOnFirstThread"]
mainClassName = 'HelloWorld.Main'
|
これでMacでも動くようになった。