0

I am currently following a game engine tutorial by ThinMatrix, this is the video https://www.youtube.com/watch?v=VS8wlS9hF8E&t=97s, and I keep getting this error:

Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/Unsafe
    at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.getUnsafeInstance(MemoryUtilSun.java:74)
    at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.<init>(MemoryUtilSun.java:62)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
    at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347)
    at java.base/java.lang.Class.newInstance(Class.java:645)
    at lwjgl/org.lwjgl.MemoryUtil.loadAccessor(MemoryUtil.java:375)
    at lwjgl/org.lwjgl.MemoryUtil.<clinit>(MemoryUtil.java:63)
    at lwjgl/org.lwjgl.opengl.WindowsDisplay.setTitle(WindowsDisplay.java:523)
    at lwjgl/org.lwjgl.opengl.Display.setTitle(Display.java:541)
    at lwjgl/org.lwjgl.opengl.Display.createWindow(Display.java:312)
    at lwjgl/org.lwjgl.opengl.Display.create(Display.java:848)
    at lwjgl/org.lwjgl.opengl.Display.create(Display.java:797)
    at GameEngine/renderEngine.DisplayManager.createDisplay(DisplayManager.java:20)
    at GameEngine/engineTester.MainGameLoop.main(MainGameLoop.java:10)
Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 18 more

I have tried using both Java JRE 14 and Java JRE 17, both of these give me the same error. I tried reinstalling both of the above motioned JREs.

Does anyone have a solution to this?

1 Answers1

1

There is no good solution to this.

The correct solution is to find and use a version of lwjgl that doesn't use Unsafe. (There may be one, but I couldn't figure it out from the release notes.)

The hack solution (for Java 17) is to use an --add-opens option to smash through the access control barriers that they have added to stop people using Unsafe.

However, as the comments on In Java 17 how do I avoid resorting to --add-opens? point out, this is at best a short term fix.

You shouldn't use Java 14. It is end-of-life.

You could roll back to an earlier LTS version of Java (Java 8 or 11) but that stops you from using newer Java features, and they will eventually go end-of-life anyway. So this is not a good solution.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216