Hello Guest

[SOLVED] Game won't start on MacOS (and sometimes Windows?)

  • 6 Replies
  • 5512 Views
*

Offline Danjb

  • *
  • 18
I am trying to get my game to run on MacOS but I'm seeing the following error:

Code: [Select]
    Exception in thread "main" java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1023)
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
        at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:176)
        at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1105)
        at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1086)
        at java.base/java.lang.reflect.Field.getInt(Field.java:594)
        at org.lwjgl.system.APIUtil.apiClassTokens(APIUtil.java:308)
        at org.lwjgl.glfw.GLFWErrorCallback$1.<init>(GLFWErrorCallback.java:98)
        at org.lwjgl.glfw.GLFWErrorCallback.createPrint(GLFWErrorCallback.java:97)
        at client.launcher.ClientLauncher.<init>(ClientLauncher.java:178)
        at main.AbacusLauncher.<init>(AbacusLauncher.java:49)
        at main.AbacusLauncher.main(AbacusLauncher.java:81)
    Caused by: java.lang.NullPointerException
        at org.lwjgl.system.Checks.check(Checks.java:99)
        at org.lwjgl.system.Pointer$Default.<init>(Pointer.java:52)
        at org.lwjgl.system.SharedLibrary$Default.<init>(SharedLibrary.java:18)
        at org.lwjgl.system.macosx.MacOSXLibrary.<init>(MacOSXLibrary.java:15)
        at org.lwjgl.system.macosx.MacOSXLibraryDL.<init>(MacOSXLibraryDL.java:19)
        at org.lwjgl.system.macosx.MacOSXLibrary.create(MacOSXLibrary.java:28)
        at org.lwjgl.system.APIUtil.apiCreateLibrary(APIUtil.java:126)
        at org.lwjgl.system.Library.loadNativeFromSystem(Library.java:300)
        at org.lwjgl.system.Library.loadNative(Library.java:286)
        at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:659)

I am running my game using:

Code: [Select]
java -Djava.library.path="libs/" -jar abacus.jar -XStartOnFirstThread
In the "libs" folder I have the following:

Code: [Select]
jorbis-0.0.17.jar
lwjgl-3.1.6.jar
lwjgl-3.1.6-natives-macos.jar
lwjgl-glfw-3.1.6.jar
lwjgl-glfw-natives-macos.jar
lwjgl-openal-3.1.6.jar
lwjgl-openal-natives-macos.jar
lwjgl-opengl-3.1.6.jar
lwjgl-opengl-natives-macos.jar

And my manifest:

Code: [Select]
Manifest-Version: 1.0
Class-Path: libs/lwjgl-3.1.6.jar libs/lwjgl-glfw-3.1.6.jar libs/lwjgl-
 openal-3.1.6.jar libs/lwjgl-opengl-3.1.6.jar libs/lwjgl-3.1.6-natives
 -macos.jar libs/lwjgl-glfw.3.1.6-natives-macos.jar libs/lwjgl-openal.
 3.1.6-natives-macos.jar libs/lwjgl-opengl.3.1.6-natives-macos.jar lib
 s/jorbis-0.0.17.jar
Main-Class: main.AbacusLauncher

Does anyone know what might cause this?

Many thanks,
Dan

EDIT: A friend of mine is seeing the exact same issue on Windows, but the game runs fine for me. Here's the Windows version of the error:

Code: [Select]
Exception in thread "main" java.lang.ExceptionInInitializerError
        at sun.misc.Unsafe.ensureClassInitialized(Native Method)
        at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(Unknown Source)
        at sun.reflect.ReflectionFactory.newFieldAccessor(Unknown Source)
        at java.lang.reflect.Field.acquireFieldAccessor(Unknown Source)
        at java.lang.reflect.Field.getFieldAccessor(Unknown Source)
        at java.lang.reflect.Field.getInt(Unknown Source)
        at org.lwjgl.system.APIUtil.apiClassTokens(APIUtil.java:308)
        at org.lwjgl.glfw.GLFWErrorCallback$1.<init>(GLFWErrorCallback.java:98)
        at org.lwjgl.glfw.GLFWErrorCallback.createPrint(GLFWErrorCallback.java:97)
        at client.launcher.ClientLauncher.<init>(ClientLauncher.java:178)
        at main.AbacusLauncher.<init>(AbacusLauncher.java:49)
        at main.AbacusLauncher.main(AbacusLauncher.java:81)
Caused by: java.lang.NullPointerException
        at org.lwjgl.system.Checks.check(Checks.java:99)
        at org.lwjgl.system.Pointer$Default.<init>(Pointer.java:52)
        at org.lwjgl.system.SharedLibrary$Default.<init>(SharedLibrary.java:18)
        at org.lwjgl.system.windows.WindowsLibrary.<init>(WindowsLibrary.java:32)
        at org.lwjgl.system.APIUtil.apiCreateLibrary(APIUtil.java:122)
        at org.lwjgl.system.Library.loadNativeFromSystem(Library.java:300)
        at org.lwjgl.system.Library.loadNative(Library.java:286)
        at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:659)
        ... 12 more
« Last Edit: July 22, 2018, 07:05:23 by Danjb »

*

Offline KaiHH

  • ****
  • 334
Re: Game won't start on MacOS (and sometimes Windows?)
« Reply #1 on: July 20, 2018, 21:25:11 »
Code: [Select]
java -Djava.library.path="libs/" -jar abacus.jar -XStartOnFirstThread
First of all, the above should read:
Code: [Select]
java -Djava.library.path="libs/" -XstartOnFirstThread -jar abacus.jarEverything after "-jar thejar.jar" will be treated as program command line argument passed on main(String[] args) and not as java launcher argument, so it will not be effective with your call.

Next:
In the "libs" folder I have the following:
Code: [Select]
jorbis-0.0.17.jar
lwjgl-3.1.6.jar
lwjgl-3.1.6-natives-macos.jar
lwjgl-glfw-3.1.6.jar
lwjgl-glfw-natives-macos.jar
lwjgl-openal-3.1.6.jar
lwjgl-openal-natives-macos.jar
lwjgl-opengl-3.1.6.jar
lwjgl-opengl-natives-macos.jar

And my manifest:

Code: [Select]
Manifest-Version: 1.0
Class-Path: libs/lwjgl-3.1.6.jar libs/lwjgl-glfw-3.1.6.jar libs/lwjgl-
 openal-3.1.6.jar libs/lwjgl-opengl-3.1.6.jar libs/lwjgl-3.1.6-natives
 -macos.jar libs/lwjgl-glfw.3.1.6-natives-macos.jar libs/lwjgl-openal.
 3.1.6-natives-macos.jar libs/lwjgl-opengl.3.1.6-natives-macos.jar lib
 s/jorbis-0.0.17.jar
Main-Class: main.AbacusLauncher

Many of your classpath entries do not match the file in the file system directory.
For example:
- the file says: libs/lwjgl-openal-natives-macos.jar but the classpath entry says: libs/lwjgl-openal.3.1.6-natives-macos.jar
- the file says: libs/lwjgl-glfw-natives-macos.jar but the classpath entry says: libs/lwjgl-glfw.3.1.6-natives-macos.jar
- the file says: libs/lwjgl-opengl-natives-macos.jar but the classpath entry says: libs/lwjgl-opengl.3.1.6-natives-macos.jar

*

Offline Danjb

  • *
  • 18
Re: Game won't start on MacOS (and sometimes Windows?)
« Reply #2 on: July 20, 2018, 21:51:45 »
Thanks a lot for the quick reply, this was driving me nuts. It's working now... and I feel like an idiot since the answer was staring me in the face this whole time ;D

Strangely, it was running for me even with the dodgy manifest - I still don't understand why.

*

Offline KaiHH

  • ****
  • 334
Re: Game won't start on MacOS (and sometimes Windows?)
« Reply #3 on: July 20, 2018, 21:54:38 »
Strangely, it was running for me even with the dodgy manifest - I still don't understand why.
Yeah, I feel you. This is likely because you ran the app from your IDE with a proper classpath previously, making LWJGL3 extract the shared library files inside of the natives jars into a temporary folder in your user's directory. Then, when the jar is not in the runtime classpath anymore but a matching extracted shared library still exists in the temporary folder, that will be loaded silently without the jar needed. This has caused some wondering moments for me too.

*

Offline Danjb

  • *
  • 18
Re: Game won't start on MacOS (and sometimes Windows?)
« Reply #4 on: July 20, 2018, 22:24:54 »
Strangely, it was running for me even with the dodgy manifest - I still don't understand why.
This is likely because you ran the app from your IDE with a proper classpath previously, making LWJGL3 extract the shared library files inside of the natives jars into a temporary folder in your user's directory. Then, when the jar is not in the runtime classpath anymore but a matching extracted shared library still exists in the temporary folder, that will be loaded silently without the jar needed. This has caused some wondering moments for me too.

I was able to run it using the same distribution that I sent to my friends, built with Gradle. Extracted the ZIP to a clean directory and it just worked. I can only assume Java was somehow finding the library files from elsewhere on my computer, but I have no idea how or where.

*

Offline KaiHH

  • ****
  • 334
Re: Game won't start on MacOS (and sometimes Windows?)
« Reply #5 on: July 20, 2018, 22:32:03 »
You don't need to assume. I just outlined you the algorithm LWJGL3 is using which made it work.
Look in your temporary folder inside of your user's directory for a folder called "lwjgl<your-user-name>".

EDIT: See this class which handles the shared library extracting and loading: https://github.com/LWJGL/lwjgl3/blob/master/modules/lwjgl/core/src/main/java/org/lwjgl/system/SharedLibraryLoader.java
« Last Edit: July 20, 2018, 22:37:20 by KaiHH »

*

Offline Danjb

  • *
  • 18
Re: Game won't start on MacOS (and sometimes Windows?)
« Reply #6 on: July 20, 2018, 23:05:53 »
Ah I see now, thanks for the info :)