LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: tomera on December 26, 2016, 23:48:05

Title: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: tomera on December 26, 2016, 23:48:05
I try to use LWJGL3 with eclipse but I have runtime compile error related to the native. I downloaded the latest release (3.1.0 build 40) and included the native and the code jars in the build path as seen in the screen shot:

(https://i.stack.imgur.com/1iyYv.png)

* yes I checked in order and export that they are marked.

However when running the code HelloWorld code I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.system.MemoryAccess
at org.lwjgl.system.Pointer.<clinit>(Pointer.java:22)
at org.lwjgl.system.Platform.mapLibraryNameBundled(Platform.java:76)
at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:563)
at gpu.HelloWorld.run(HelloWorld.java:29)
at gpu.HelloWorld.main(HelloWorld.java:100)


I have looked here, stackoverflow and google and could not find the answer.

- I tried to set the native put the native (the .so file outside the jar) and it not working.
- I tried using  -Djava.library.path and the path to the .so files and it not working

My linux OS is centos.

What am I doing wrong?

Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: spasi on December 27, 2016, 08:29:23
Try running with -Dorg.lwjgl.util.Debug=true and -Dorg.lwjgl.util.DebugLoader=true and inspect the output for an explanation of what might be wrong.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: tomera on December 27, 2016, 11:29:35
This is the error I get:

[LWJGL] Version: 3.1.0 build 40
[LWJGL] OS: Linux v2.6.32-504.23.4.el6.centos.plus.x86_64
[LWJGL] JRE: 1.8.0_111 amd64
[LWJGL] JVM: Java HotSpot(TM) 64-Bit Server VM v25.111-b14 by Oracle Corporation
[LWJGL] Loading library (system): lwjgl
[LWJGL] Found at: /tmp/lwjgltaviad/3.1.0-build-40/liblwjgl.so
[LWJGL] [TLS] Failed to initialize unsafe implementation.
[LWJGL] ThreadLocalUtil state: TLState
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.system.Library
at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:56)
at org.lwjgl.system.MemoryStack.<init>(MemoryStack.java:57)
at org.lwjgl.system.MemoryStack.create(MemoryStack.java:76)
at org.lwjgl.system.MemoryStack.create(MemoryStack.java:67)
at org.lwjgl.system.ThreadLocalState.<init>(ThreadLocalState.java:24)
at org.lwjgl.system.ThreadLocalUtil$TLState$1.initialValue(ThreadLocalUtil.java:61)
at org.lwjgl.system.ThreadLocalUtil$TLState$1.initialValue(ThreadLocalUtil.java:58)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
at java.lang.ThreadLocal.get(ThreadLocal.java:170)
at org.lwjgl.system.ThreadLocalUtil$TLState.get(ThreadLocalUtil.java:72)
at org.lwjgl.system.ThreadLocalUtil.tlsGet(ThreadLocalUtil.java:30)
at org.lwjgl.system.MemoryStack.stackPush(MemoryStack.java:589)
at gpu.CLDemo.main(CLDemo.java:28)

Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: spasi on December 27, 2016, 11:53:01
Unfortunately there is an exception during class initialization and the stacktrace is not helpful. The message "Failed to initialize unsafe implementation" is also odd.

Does it work with a simpler demo? E.g. the getting started sample (https://www.lwjgl.org/guide) on the website.

Also, could you please try the same with an LWJGL 3.1.1 snapshot?
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: tomera on December 27, 2016, 14:16:52
I can only test it next week.

It may be relate to the user permissions? I dont have root/sudo permissions on my user.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: tomera on January 01, 2017, 11:33:41
This the error I get when I run what you told me:

[LWJGL] Version: 3.1.2 build 1
[LWJGL] OS: Linux v2.6.32-504.23.4.el6.centos.plus.x86_64
[LWJGL] JRE: 1.8.0_111 amd64
[LWJGL] JVM: Java HotSpot(TM) 64-Bit Server VM v25.111-b14 by Oracle Corporation
[LWJGL] Loading library (system): lwjgl
[LWJGL] Found at: /tmp/lwjgltaviad/3.1.2-build-1/liblwjgl.so
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.system.Library
at org.lwjgl.system.MemoryAccessJNI.<clinit>(MemoryAccessJNI.java:13)
at org.lwjgl.system.Pointer.<clinit>(Pointer.java:22)
at org.lwjgl.system.Platform.mapLibraryNameBundled(Platform.java:76)
at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:566)
at test2.HelloWorld.run(HelloWorld.java:29)
at test2.HelloWorld.main(HelloWorld.java:105)
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: tomera on January 01, 2017, 12:03:05
When running only this code:

public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");

init();

}


I get this error:


Hello LWJGL 3.1.2 build 1!
Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/lwjgltaviad/3.1.2-build-1/liblwjgl.so: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /tmp/lwjgltaviad/3.1.2-build-1/liblwjgl.so)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at org.lwjgl.system.Library.loadSystem(Library.java:138)
at org.lwjgl.system.Library.loadSystem(Library.java:128)
at org.lwjgl.system.Library.loadSystem(Library.java:96)
at org.lwjgl.system.Library.<clinit>(Library.java:53)
at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:56)
at org.lwjgl.system.MemoryStack.<init>(MemoryStack.java:59)
at org.lwjgl.system.MemoryStack.create(MemoryStack.java:78)
at org.lwjgl.system.MemoryStack.create(MemoryStack.java:69)
at java.lang.ThreadLocal$SuppliedThreadLocal.initialValue(ThreadLocal.java:284)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
at java.lang.ThreadLocal.get(ThreadLocal.java:170)
at org.lwjgl.system.MemoryStack.stackGet(MemoryStack.java:594)
at org.lwjgl.system.MemoryStack.stackPush(MemoryStack.java:603)
at org.lwjgl.system.Callback.<clinit>(Callback.java:35)
at test.HelloWorld.init(HelloWorld.java:27)
at test.HelloWorld.run(HelloWorld.java:20)
at test.HelloWorld.main(HelloWorld.java:95)


Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: Kai on January 01, 2017, 12:14:50
Google found this: http://unix.stackexchange.com/questions/176489/how-to-update-glibc-to-2-14-in-centos-6-5
Probably the first answer is a workaround for you.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: tomera on January 01, 2017, 12:21:57
Why its related to me?
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: Kai on January 01, 2017, 12:25:10
Because apparently it is the same cause: Requiring glibc 2.14, and you are running centos.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: tomera on January 01, 2017, 12:29:08
I see, ok thank you, ill try it.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: spasi on January 01, 2017, 13:09:10
Hmm, is this a problem with how LWJGL is built? Any Linux expert around?
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: Kai on January 01, 2017, 13:13:00
Looks like this is the way to go: http://stackoverflow.com/questions/4032373/linking-against-an-old-version-of-libc-to-provide-greater-application-coverage
Same: http://stackoverflow.com/questions/2856438/how-can-i-link-to-a-specific-glibc-version


$ objdump -p liblwjgl.so
...
Version References:
  required from libpthread.so.0:
    0x09691a75 0x00 03 GLIBC_2.2.5
  required from libc.so.6:
    0x09691974 0x00 06 GLIBC_2.3.4
    0x0d696917 0x00 05 GLIBC_2.7
    0x06969194 0x00 04 GLIBC_2.14
    0x09691a75 0x00 02 GLIBC_2.2.5

$ objdump -T liblwjgl.so | fgrep GLIBC_2.14
0000000000000000      DF *UND* 0000000000000000  GLIBC_2.14  memcpy

$ objdump -T /lib/x86_64-linux-gnu/libc.so.6 | grep -w memcpy
0000000000093840 g   iD  .text 000000000000006a  GLIBC_2.14  memcpy
000000000008e59b g   iD  .text 0000000000000057 (GLIBC_2.2.5) memcpy
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: sf17k on January 01, 2017, 19:24:45
Same error on Ubuntu 16. I'm making a libgdx game built with gradle and sending it to testers on various systems. Just updated libgdx from 1.9.3 to 1.9.5, which also updated LWJGL from 3.0.0b to 3.1.0, and now my Ubuntu 16 tester can no longer run the game. It works fine on Mac and Windows, even Windows XP.

Can do more testing to confirm.

EDIT: Yep, downgrading libgdx back to 1.9.3 (and LWJGL to 3.0.0b) fixes the problem.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: spasi on January 01, 2017, 22:36:31
Could you please post the output with -Dorg.lwjgl.util.Debug=true and -Dorg.lwjgl.util.DebugLoader=true? I don't think it's the same error.

Could you also please post the output of ldd --version?
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: sf17k on January 04, 2017, 18:46:12
Results attached.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: spasi on January 04, 2017, 19:38:05
@sf17k That indeed looks like a different error, but an exception is probably being swallowed. Could you run a simpler test please? E.g. a simple call to glfwInit() or the getting started sample (https://www.lwjgl.org/guide).

@tomera I've been making progress with your issue, it is not trivial to fix. Will post as soon as a build that fixes it is available.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: sf17k on January 05, 2017, 13:55:20
Here it is simply calling glfwInit().

EDIT: The classpath section of the start script (generated by gradle):
CLASSPATH=$APP_HOME/lib/client.jar:$APP_HOME/lib/kotlin-stdlib-1.0.5.jar:$APP_HOME/lib/gdx-1.9.5.jar:$APP_HOME/lib/gdx-backend-lwjgl3-1.9.5.jar:$APP_HOME/lib/gdx-platform-1.9.5-natives-desktop.jar:$APP_HOME/lib/gdx-tools-1.9.5.jar:$APP_HOME/lib/kotlin-runtime-1.0.5.jar:$APP_HOME/lib/lwjgl-3.1.0.jar:$APP_HOME/lib/lwjgl-3.1.0-natives-windows.jar:$APP_HOME/lib/lwjgl-3.1.0-natives-linux.jar:$APP_HOME/lib/lwjgl-3.1.0-natives-macos.jar:$APP_HOME/lib/lwjgl-glfw-3.1.0.jar:$APP_HOME/lib/lwjgl-glfw-3.1.0-natives-windows.jar:$APP_HOME/lib/lwjgl-glfw-3.1.0-natives-linux.jar:$APP_HOME/lib/lwjgl-glfw-3.1.0-natives-macos.jar:$APP_HOME/lib/lwjgl-jemalloc-3.1.0.jar:$APP_HOME/lib/lwjgl-jemalloc-3.1.0-natives-windows.jar:$APP_HOME/lib/lwjgl-jemalloc-3.1.0-natives-linux.jar:$APP_HOME/lib/lwjgl-jemalloc-3.1.0-natives-macos.jar:$APP_HOME/lib/lwjgl-opengl-3.1.0.jar:$APP_HOME/lib/lwjgl-openal-3.1.0.jar:$APP_HOME/lib/lwjgl-openal-3.1.0-natives-windows.jar:$APP_HOME/lib/lwjgl-openal-3.1.0-natives-linux.jar:$APP_HOME/lib/lwjgl-openal-3.1.0-natives-macos.jar:$APP_HOME/lib/jlayer-1.0.1-gdx.jar:$APP_HOME/lib/jorbis-0.0.17.jar:$APP_HOME/lib/gdx-backend-lwjgl-1.9.5.jar:$APP_HOME/lib/gdx-backend-headless-1.9.5.jar:$APP_HOME/lib/gdx-freetype-1.9.5.jar:$APP_HOME/lib/gdx-freetype-platform-1.9.5-natives-desktop.jar:$APP_HOME/lib/lwjgl-2.9.2.jar:$APP_HOME/lib/lwjgl_util-2.9.2.jar:$APP_HOME/lib/lwjgl-platform-2.9.2-natives-windows.jar:$APP_HOME/lib/lwjgl-platform-2.9.2-natives-linux.jar:$APP_HOME/lib/lwjgl-platform-2.9.2-natives-osx.jar:$APP_HOME/lib/jinput-2.0.5.jar:$APP_HOME/lib/jutils-1.0.0.jar:$APP_HOME/lib/jinput-platform-2.0.5-natives-linux.jar:$APP_HOME/lib/jinput-platform-2.0.5-natives-windows.jar:$APP_HOME/lib/jinput-platform-2.0.5-natives-osx.jar
Reformatted for ease of reading:
client.jar
kotlin-stdlib-1.0.5.jar
gdx-1.9.5.jar
gdx-backend-lwjgl3-1.9.5.jar
gdx-platform-1.9.5-natives-desktop.jar
gdx-tools-1.9.5.jar
kotlin-runtime-1.0.5.jar
lwjgl-3.1.0.jar
lwjgl-3.1.0-natives-windows.jar
lwjgl-3.1.0-natives-linux.jar
lwjgl-3.1.0-natives-macos.jar
lwjgl-glfw-3.1.0.jar
lwjgl-glfw-3.1.0-natives-windows.jar
lwjgl-glfw-3.1.0-natives-linux.jar
lwjgl-glfw-3.1.0-natives-macos.jar
lwjgl-jemalloc-3.1.0.jar
lwjgl-jemalloc-3.1.0-natives-windows.jar
lwjgl-jemalloc-3.1.0-natives-linux.jar
lwjgl-jemalloc-3.1.0-natives-macos.jar
lwjgl-opengl-3.1.0.jar
lwjgl-openal-3.1.0.jar
lwjgl-openal-3.1.0-natives-windows.jar
lwjgl-openal-3.1.0-natives-linux.jar
lwjgl-openal-3.1.0-natives-macos.jar
jlayer-1.0.1-gdx.jar
jorbis-0.0.17.jar
gdx-backend-lwjgl-1.9.5.jar
gdx-backend-headless-1.9.5.jar
gdx-freetype-1.9.5.jar
gdx-freetype-platform-1.9.5-natives-desktop.jar
lwjgl-2.9.2.jar
lwjgl_util-2.9.2.jar
lwjgl-platform-2.9.2-natives-windows.jar
lwjgl-platform-2.9.2-natives-linux.jar
lwjgl-platform-2.9.2-natives-osx.jar
jinput-2.0.5.jar
jutils-1.0.0.jar
jinput-platform-2.0.5-natives-linux.jar
jinput-platform-2.0.5-natives-windows.jar
jinput-platform-2.0.5-natives-osx.jar
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: spasi on January 05, 2017, 14:39:12
Oh, you're on 32-bit Linux. I should have noticed the "i386" in your previous post. I'm afraid the default LWJGL distribution does not come with 32-bit Linux binaries, see #162 (https://github.com/LWJGL/lwjgl3/issues/162). It should be possible to build it on your own, though I haven't tried it lately. Let me know if you face any issues.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: sf17k on January 05, 2017, 21:31:05
Got it. Will probably have to build it eventually, since this will be a commercial game aiming at compatibility with a fairly wide range of systems. There's even Windows XP support! In the meantime, using a previous version of LWJGL should suffice.
Title: Re: Could not initialize class org.lwjgl.system.MemoryAccess
Post by: spasi on January 06, 2017, 18:11:44
@tomera

LWJGL 3.1.2 build #2 is now available. The dependencies on newer GLIBC versions have been eliminated in all shared libraries and it should work on your system. Could you please verify?