Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer with FFIClosure, using hashmap-based ClosureRegistry. #720

Closed
mindstorm38 opened this issue Jan 22, 2022 · 7 comments
Closed

Comments

@mindstorm38
Copy link

Version

3.3.0 (nightly)

Platform

Linux arm32

JDK

OpenJDK 17.0.1 2021-10-19 LTS

Module

Core, GLFW

Bug description

This issue is related to Minecraft, I'm trying to run it on my RPi 400, which run on Debian, ARMv7 (32 bits). I got the correct shared objects in the directory specified by java.library.path (note that natives artifacts are not added to the classpath, it would be redundant), here is a screenshot of this directory:
bin_content

When starting the game, it crashes because of a NullPointerException (full crash report à the end of the issue):

java.lang.NullPointerException: Cannot invoke "org.lwjgl.system.libffi.FFIClosure.user_data()" because the return value of "org.lwjgl.system.Callback$ClosureRegistry.get(long)" is null
	at org.lwjgl.system.Callback.get(Callback.java:190)
	at org.lwjgl.glfw.GLFWErrorCallback.create(GLFWErrorCallback.java:40)
	at org.lwjgl.glfw.GLFWErrorCallback.createSafe(GLFWErrorCallback.java:49)
	at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:1288)
	at com.mojang.blaze3d.platform.GLX._setGlfwErrorCallback(SourceFile:83)
	at com.mojang.blaze3d.systems.RenderSystem.setErrorCallback(SourceFile:815)
	at com.mojang.blaze3d.platform.GLX._initGlfw(SourceFile:77)
	at com.mojang.blaze3d.systems.RenderSystem.initBackendSystem(SourceFile:804)
	at dxo.<init>(SourceFile:473)
	at net.minecraft.client.main.Main.main(SourceFile:199)

I've tested with LWJGL 3.2.3, which is the first version to come with pre-compiled ARM32 shared objects, and it works, so I supposed that it doesn't come from Minecraft, but rather from LWJGL.

If you are interested, I also captured the output with -Dorg.lwjgl.util.Debug=true and -Dorg.lwjgl.util.DebugAllocator=true (I stripped useless Minecraft outputs): lwjgl_with_debug.txt

Stacktrace or crash log output

---- Minecraft Crash Report ----
// I bet Cylons wouldn't have this problem.

Time: 22/01/2022 14:24
Description: Initializing game

java.lang.NullPointerException: Cannot invoke "org.lwjgl.system.libffi.FFIClosure.user_data()" because the return value of "org.lwjgl.system.Callback$ClosureRegistry.get(long)" is null
	at org.lwjgl.system.Callback.get(Callback.java:190)
	at org.lwjgl.glfw.GLFWErrorCallback.create(GLFWErrorCallback.java:40)
	at org.lwjgl.glfw.GLFWErrorCallback.createSafe(GLFWErrorCallback.java:49)
	at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:1288)
	at com.mojang.blaze3d.platform.GLX._setGlfwErrorCallback(SourceFile:83)
	at com.mojang.blaze3d.systems.RenderSystem.setErrorCallback(SourceFile:815)
	at com.mojang.blaze3d.platform.GLX._initGlfw(SourceFile:77)
	at com.mojang.blaze3d.systems.RenderSystem.initBackendSystem(SourceFile:804)
	at dxo.<init>(SourceFile:473)
	at net.minecraft.client.main.Main.main(SourceFile:199)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at org.lwjgl.system.Callback.get(Callback.java:190)
	at org.lwjgl.glfw.GLFWErrorCallback.create(GLFWErrorCallback.java:40)
	at org.lwjgl.glfw.GLFWErrorCallback.createSafe(GLFWErrorCallback.java:49)
	at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:1288)
	at com.mojang.blaze3d.platform.GLX._setGlfwErrorCallback(SourceFile:83)
	at com.mojang.blaze3d.systems.RenderSystem.setErrorCallback(SourceFile:815)
	at com.mojang.blaze3d.platform.GLX._initGlfw(SourceFile:77)
	at com.mojang.blaze3d.systems.RenderSystem.initBackendSystem(SourceFile:804)
	at dxo.<init>(SourceFile:473)

-- Initialization --
Details:
	Modules: 
Stacktrace:
	at net.minecraft.client.main.Main.main(SourceFile:199)

-- System Details --
Details:
	Minecraft Version: 1.18.1
	Minecraft Version ID: 1.18.1
	Operating System: Linux (arm) version 5.10.63-v7l+
	Java Version: 17.0.1, BellSoft
	Java VM Version: OpenJDK Server VM (mixed mode), BellSoft
	Memory: 273853400 bytes (261 MiB) / 536870912 bytes (512 MiB) up to 2147483648 bytes (2048 MiB)
	CPUs: 4
	Processor Vendor: armv7l
	Processor Name: ARMv7 Processor rev 3 (v7l)
	Identifier: armv7l Family 7 Model 0xd08 Stepping r0x0p3
	Microarchitecture: unknown
	Frequency (GHz): -0,00
	Number of physical packages: 1
	Number of physical CPUs: 1
	Number of logical CPUs: 4
	Graphics card #0 name: unknown
	Graphics card #0 vendor: unknown
	Graphics card #0 VRAM (MB): 0,00
	Graphics card #0 deviceId: unknown
	Graphics card #0 versionInfo: unknown
	Virtual memory max (MB): 2019,36
	Virtual memory used (MB): 1219,34
	Swap memory total (MB): 100,00
	Swap memory used (MB): 0,00
	JVM Flags: 7 total; -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M
	Launched Version: 1.18.1
	Backend library: LWJGL version 3.3.0 build 21
	Backend API: Unknown
	Window size: <not initialized>
	GL Caps: Using framebuffer using OpenGL 3.2
	GL debug messages: <disabled>
	Using VBOs: Yes
	Is Modded: Probably not. Client jar signature and brand is untouched
	Type: Client (map_client.txt)
	CPU: <unknown>
@Spasi
Copy link
Member

Spasi commented Jan 28, 2022

Hey @mindstorm38,

This is a weird one. The only explanation for the NPE is that glfwSetErrorCallback does not return NULL and LWJGL is not aware of the value returned. This can only happen if something has already called glfwSetErrorCallback from non-LWJGL code. However:

  1. I don't know why anyone would do that, sounds unlikely.
  2. It would also crash on LWJGL 3.2.3, the Callback.get method expected a valid dyncall callback there, instead of a libffi closure.

I would need more information to figure this out. One easy way to see if something's wrong with LWJGL is to clone it on the RPi and run some tests:

// prerequisites: install JDK 17, Apache Ant, GCC
git clone https://github.com/LWJGL/lwjgl3.git
cd lwjgl3
ant hydrate-kotlinc -Dhydrate-kotlinc.force=true
ant tests
ant demo -Dclass=org.lwjgl.demo.glfw.Gears
ant demo -Dclass=org.lwjgl.demo.glfw.Events

(hydrate-kotlinc is a much faster alternative to compile-templates, which would take forever on the RPi)

@mindstorm38
Copy link
Author

mindstorm38 commented Jan 29, 2022

Thank you for the answer, I've done that, here are my results.

First, in addition to JDK, Ant and GCC, I was missing GTK3 and I needed to manually add the -latomic flags to the linker arguments in config/linux/build.xml to successfully link shared objects.

Output of ant tests, which ends with a JVM fatal error:

pi@raspberrypi:~/Downloads/lwjgl3 $ ant tests
Buildfile: /home/pi/Downloads/lwjgl3/build.xml

init:

check-dependencies:

generate:

compile:

compile-tests:

compile-native:

compile-native-platform:
 [Compiler] arm-linux-gnueabihf-gcc --version: "arm-linux-gnueabihf-gcc (Raspbian 8.3.0-6+rpi1) 8.3.0"
[arm-linux-gnueabihf-gcc] Linking lwjgl_libdivide
[arm-linux-gnueabihf-gcc] Linking lwjgl_lmdb
[arm-linux-gnueabihf-gcc] Linking lwjgl_llvm
[arm-linux-gnueabihf-gcc] Linking lwjgl_nanovg
[arm-linux-gnueabihf-gcc] Linking lwjgl_lz4
[arm-linux-gnueabihf-gcc] Linking lwjgl
[arm-linux-gnueabihf-g++] Linking lwjgl_meshoptimizer
[arm-linux-gnueabihf-gcc] Linking lwjgl_nfd
[arm-linux-gnueabihf-gcc] Linking lwjgl_par
[arm-linux-gnueabihf-gcc] Linking lwjgl_remotery
[arm-linux-gnueabihf-gcc] Linking lwjgl_rpmalloc
[arm-linux-gnueabihf-gcc] Linking lwjgl_stb
[arm-linux-gnueabihf-g++] Linking lwjgl_tinyexr
[arm-linux-gnueabihf-gcc] Linking lwjgl_tinyfd
[arm-linux-gnueabihf-g++] Linking lwjgl_vma
[arm-linux-gnueabihf-gcc] Linking lwjgl_xxhash
[arm-linux-gnueabihf-g++] Linking lwjgl_yoga
[arm-linux-gnueabihf-gcc] Linking lwjgl_zstd
    [mkdir] Created dir: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/assimp
    [mkdir] Created dir: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/jemalloc
    [mkdir] Created dir: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/bgfx

tests:
    [Tests] [LWJGL] Version: 3.3.1 SNAPSHOT
    [Tests] [LWJGL] 	 OS: Linux v5.10.63-v7l+
    [Tests] [LWJGL] 	JRE: Linux arm 17.0.1
    [Tests] [LWJGL] 	JVM: OpenJDK Server VM v17.0.1+12-LTS by BellSoft
    [Tests] [LWJGL] Loading JNI library: lwjgl
    [Tests] [LWJGL] 	Module: org.lwjgl
    [Tests] [LWJGL] 	Loaded from classpath: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/liblwjgl.so
    [Tests] [LWJGL] Loading library: lwjgl
    [Tests] [LWJGL] 	Module: org.lwjgl
    [Tests] [LWJGL] 	Loaded from classpath: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/liblwjgl.so
    [Tests] [LWJGL] Loading library: jemalloc
    [Tests] [LWJGL] 	Module: org.lwjgl.jemalloc
    [Tests] [LWJGL] 	Loaded from classpath: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/jemalloc/libjemalloc.so
    [Tests] [LWJGL] Closure Registry: ConcurrentHashMap
    [Tests] [LWJGL] MemoryUtil allocator: DebugAllocator
    [Tests] [LWJGL] [WARNING] Out of frame stack space (8) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (12) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (18) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (27) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (40) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (60) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (90) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (135) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (202) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (303) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (454) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (681) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (1021) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (1531) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (2296) in thread: Thread[main,5,main]
    [Tests] [LWJGL] [WARNING] Out of frame stack space (3444) in thread: Thread[main,5,main]
    [Tests] [LWJGL] Loading JNI library: lwjgl_libdivide
    [Tests] [LWJGL] 	Module: org.lwjgl.libdivide
    [Tests] [LWJGL] 	Loaded from classpath: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/libdivide/liblwjgl_libdivide.so
    [Tests] [LWJGL] Loading JNI library: lwjgl_meshoptimizer
    [Tests] [LWJGL] 	Module: org.lwjgl.meshoptimizer
    [Tests] [LWJGL] 	Loaded from classpath: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/meshoptimizer/liblwjgl_meshoptimizer.so
    [Tests] [LWJGL] Loading library: OpenCL
    [Tests] [LWJGL] 	Module: org.lwjgl.opencl
    [Tests] [LWJGL] 	libOpenCL.so not found in system paths
    [Tests] [LWJGL] 	libOpenCL.so not found in java.library.path=/usr/java/packages/lib:/lib:/usr/lib
    [Tests] [LWJGL] Failed to load a library. Possible solutions:
    [Tests] 	a) Install the library or the driver that provides the library.
    [Tests] 	b) Ensure that the library is accessible from the system library paths.
    [Tests] [LWJGL] Loading library: opus
    [Tests] [LWJGL] 	Module: org.lwjgl.opus
    [Tests] [LWJGL] 	Loaded from classpath: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/opus/libopus.so
    [Tests] [LWJGL] Loading JNI library: lwjgl_par
    [Tests] [LWJGL] 	Module: org.lwjgl.par
    [Tests] [LWJGL] 	Loaded from classpath: /home/pi/Downloads/lwjgl3/bin/libs/native/linux/arm32/org/lwjgl/par/liblwjgl_par.so
    [Tests] #
    [Tests] # A fatal error has been detected by the Java Runtime Environment:
    [Tests] #
    [Tests] #  SIGSEGV (0xb) at pc=0xb6f97c8c, pid=12221, tid=12224
    [Tests] #
    [Tests] # JRE version: OpenJDK Runtime Environment (17.0.1+12) (build 17.0.1+12-LTS)
    [Tests] # Java VM: OpenJDK Server VM (17.0.1+12-LTS, mixed mode, g1 gc, linux-arm)
    [Tests] # Problematic frame:
    [Tests] # C  [libarmmem-v7l.so+0x1c8c]
    [Tests] #
    [Tests] # No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
    [Tests] #
    [Tests] # An error report file with more information is saved as:
    [Tests] # /home/pi/Downloads/lwjgl3/hs_err_pid12221.log
    [Tests] #
    [Tests] # If you would like to submit a bug report, please visit:
    [Tests] #   https://bell-sw.com/support
    [Tests] # The crash happened outside the Java Virtual Machine in native code.
    [Tests] # See problematic frame for where to report the bug.
    [Tests] #

BUILD SUCCESSFUL
Total time: 3 minutes 14 seconds

Output of Gears demo:

pi@raspberrypi:~/Downloads/lwjgl3 $ ant demo -Dclass=org.lwjgl.demo.glfw.Gears
Buildfile: /home/pi/Downloads/lwjgl3/build.xml

init:

check-dependencies:

generate:

compile:

compile-tests:

compile-native:

compile-native-platform:
 [Compiler] arm-linux-gnueabihf-gcc --version: "arm-linux-gnueabihf-gcc (Raspbian 8.3.0-6+rpi1) 8.3.0"

-update-assets:

update-assets:
   [Assets] Updating...
    [mkdir] Created dir: /home/pi/Downloads/lwjgl3/modules/samples/src/test/resources/demo/nanovg/images
[NanoVG asset images/image10.jpg] https://github.com/memononen/nanovg/raw/master/example/images/image10.jpg moved to https://raw.githubusercontent.com/memononen/nanovg/master/example/images/image10.jpg
[NanoVG asset images/image12.jpg] https://github.com/memononen/nanovg/raw/master/example/images/image12.jpg moved to https://raw.githubusercontent.com/memononen/nanovg/master/example/images/image12.jpg
[NanoVG asset images/image11.jpg] https://github.com/memononen/nanovg/raw/master/example/images/image11.jpg moved to https://raw.githubusercontent.com/memononen/nanovg/master/example/images/image11.jpg
    [touch] Creating /home/pi/Downloads/lwjgl3/modules/samples/src/test/resources/demo/touch.txt
   [Assets] DONE

demo:
     [Demo] GL_VENDOR: Broadcom
     [Demo] GL_RENDERER: V3D 4.2
     [Demo] GL_VERSION: 2.1 Mesa 19.3.2
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_FRAGMENT shader: 12 inst, 4 threads, 0 loops, 0 uniforms, 4 max-temps, 0:0 spills:fills, 0 sfu-stalls, 12 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_VERTEX shader: 24 inst, 4 threads, 0 loops, 5 uniforms, 6 max-temps, 0:0 spills:fills, 0 sfu-stalls, 24 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_COORD shader: 19 inst, 4 threads, 0 loops, 2 uniforms, 5 max-temps, 0:0 spills:fills, 0 sfu-stalls, 19 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_FRAGMENT shader: 9 inst, 4 threads, 0 loops, 4 uniforms, 5 max-temps, 0:0 spills:fills, 0 sfu-stalls, 9 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_VERTEX shader: 72 inst, 4 threads, 0 loops, 32 uniforms, 11 max-temps, 0:0 spills:fills, 0 sfu-stalls, 72 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_COORD shader: 41 inst, 4 threads, 0 loops, 18 uniforms, 10 max-temps, 0:0 spills:fills, 0 sfu-stalls, 41 inst-and-stalls
     [Demo] 43 fps
     [Demo] 61 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 285 frames in 5 seconds = 57,00 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 300 frames in 5 seconds = 60,00 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 60 fps
     [Demo] 61 fps
     [Demo] 60 fps
     [Demo] 300 frames in 5 seconds = 60,00 fps
     [Demo] java.lang.NullPointerException: Cannot invoke "org.lwjgl.system.libffi.FFIClosure.user_data()" because "closure" is null
     [Demo] 	at org.lwjgl.system.Callback.free(Callback.java:211)
     [Demo] 	at org.lwjgl.glfw.Callbacks.glfwFreeCallbacks(Callbacks.java:55)
     [Demo] 	at org.lwjgl.demo.glfw.Gears.destroy(Gears.java:230)
     [Demo] 	at org.lwjgl.demo.glfw.Gears.run(Gears.java:47)
     [Demo] 	at org.lwjgl.demo.glfw.Gears.main(Gears.java:37)

BUILD SUCCESSFUL
Total time: 32 seconds

Output of Events demo:

pi@raspberrypi:~/Downloads/lwjgl3 $ ant demo -Dclass=org.lwjgl.demo.glfw.Events
Buildfile: /home/pi/Downloads/lwjgl3/build.xml

init:

check-dependencies:

generate:

compile:

compile-tests:

compile-native:

compile-native-platform:
 [Compiler] arm-linux-gnueabihf-gcc --version: "arm-linux-gnueabihf-gcc (Raspbian 8.3.0-6+rpi1) 8.3.0"

-update-assets:

demo:
     [Demo] ---- [ Error callback test ] ----
     [Demo] [LWJGL] GLFW_NOT_INITIALIZED error
     [Demo] 	Description : The GLFW library is not initialized
     [Demo] 	Stacktrace  :
     [Demo] 		org.lwjgl.glfw.GLFW.glfwDefaultWindowHints(GLFW.java:1857)
     [Demo] 		org.lwjgl.demo.glfw.Events.main(Events.java:40)
     [Demo] ---- [ Error callback done ] ----
     [Demo] GLFW initialized
     [Demo] 
     [Demo] Monitor 0:
     [Demo] ----------
     [Demo] 	Name: HDMI-1 (primary)
     [Demo] 	Current mode    : 1920 x 1080 @ 60 Hz (16:9, R8G8B8)
     [Demo] 	Content scale   : 1,000000 x 1,000000
     [Demo] 	Physical size   : 531mm x 299mm (24", 92 ppi)
     [Demo] 	Virtual position: 0, 0
     [Demo] 
     [Demo] Window opened:
     [Demo] --------------
     [Demo] 	Size: 640 x 480
     [Demo] 	Frame size: 2, 30, 0, 0
     [Demo] 	Content scale: 1,000000 x 1,000000
     [Demo] 	Framebuffer size: 640 x 480
     [Demo] 	Position: 0, 0
     [Demo] 
     [Demo] 1,127: Window [0x73587460] moved to 2, 30
     [Demo] 1,160: Window [0x73587460] moved to 2, 66
     [Demo] 1,161: Window [0x73587460] refreshed
     [Demo] 1,163: Window [0x73587460] gained focus
     [Demo] 5,501: Window [0x73587460] cursor entered
     [Demo] 5,503: Window [0x73587460] cursor moved to 631,000000, 54,000000
     [Demo] 5,510: Window [0x73587460] cursor moved to 610,000000, 54,000000
     [Demo] 5,517: Window [0x73587460] cursor moved to 580,000000, 54,000000
     [Demo] 5,535: Window [0x73587460] cursor moved to 546,000000, 54,000000
     [Demo] 5,537: Window [0x73587460] cursor moved to 514,000000, 48,000000
     [Demo] 5,542: Window [0x73587460] cursor moved to 484,000000, 42,000000
     [Demo] 5,558: Window [0x73587460] cursor moved to 456,000000, 30,000000
     [Demo] 5,561: Window [0x73587460] cursor moved to 434,000000, 20,000000
     [Demo] 5,575: Window [0x73587460] cursor moved to 412,000000, 8,000000
     [Demo] 5,578: Window [0x73587460] cursor moved to 396,000000, 0,000000
     [Demo] 5,592: Window [0x73587460] cursor left
     [Demo] 6,518: Window [0x73587460] moved to 782, 246
     [Demo] 6,861: Window [0x73587460] cursor entered
     [Demo] 6,863: Window [0x73587460] cursor moved to 373,000000, 2,000000
     [Demo] 6,870: Window [0x73587460] cursor moved to 372,000000, 5,000000
     [Demo] 6,878: Window [0x73587460] cursor moved to 370,000000, 8,000000
     [Demo] 6,885: Window [0x73587460] cursor moved to 368,000000, 10,000000
     [Demo] 6,895: Window [0x73587460] cursor moved to 365,000000, 11,000000
     [Demo] 6,910: Window [0x73587460] cursor moved to 364,000000, 13,000000
     [Demo] 6,925: Window [0x73587460] cursor moved to 362,000000, 14,000000
     [Demo] 6,942: Window [0x73587460] cursor moved to 360,000000, 16,000000
     [Demo] 6,945: Window [0x73587460] cursor moved to 357,000000, 17,000000
     [Demo] 6,962: Window [0x73587460] cursor moved to 354,000000, 21,000000
     [Demo] 6,964: Window [0x73587460] cursor moved to 351,000000, 28,000000
     [Demo] 6,980: Window [0x73587460] cursor moved to 343,000000, 39,000000
     [Demo] 6,982: Window [0x73587460] cursor moved to 340,000000, 50,000000
     [Demo] 6,984: Window [0x73587460] cursor moved to 336,000000, 63,000000
     [Demo] 7,009: Window [0x73587460] cursor moved to 333,000000, 77,000000
     [Demo] 7,015: Window [0x73587460] cursor moved to 329,000000, 93,000000
     [Demo] 7,017: Window [0x73587460] cursor moved to 326,000000, 109,000000
     [Demo] 7,020: Window [0x73587460] cursor moved to 324,000000, 123,000000
     [Demo] 7,023: Window [0x73587460] cursor moved to 322,000000, 141,000000
     [Demo] 7,025: Window [0x73587460] cursor moved to 319,000000, 153,000000
     [Demo] 7,027: Window [0x73587460] cursor moved to 319,000000, 162,000000
     [Demo] 7,041: Window [0x73587460] cursor moved to 316,000000, 171,000000
     [Demo] 7,058: Window [0x73587460] cursor moved to 316,000000, 177,000000
     [Demo] 7,074: Window [0x73587460] cursor moved to 314,000000, 181,000000
     [Demo] 7,075: Window [0x73587460] cursor moved to 310,000000, 187,000000
     [Demo] 7,091: Window [0x73587460] cursor moved to 304,000000, 194,000000
     [Demo] 7,092: Window [0x73587460] cursor moved to 297,000000, 203,000000
     [Demo] 7,108: Window [0x73587460] cursor moved to 287,000000, 213,000000
     [Demo] 7,109: Window [0x73587460] cursor moved to 274,000000, 222,000000
     [Demo] 7,114: Window [0x73587460] cursor moved to 262,000000, 230,000000
     [Demo] 7,125: Window [0x73587460] cursor moved to 252,000000, 239,000000
     [Demo] 7,127: Window [0x73587460] cursor moved to 240,000000, 247,000000
     [Demo] 7,141: Window [0x73587460] cursor moved to 231,000000, 252,000000
     [Demo] 7,143: Window [0x73587460] cursor moved to 222,000000, 258,000000
     [Demo] 7,158: Window [0x73587460] cursor moved to 211,000000, 261,000000
     [Demo] 7,159: Window [0x73587460] cursor moved to 200,000000, 264,000000
     [Demo] 7,178: Window [0x73587460] cursor moved to 189,000000, 266,000000
     [Demo] 7,179: Window [0x73587460] cursor moved to 180,000000, 266,000000
     [Demo] 7,191: Window [0x73587460] cursor moved to 174,000000, 266,000000
     [Demo] 7,194: Window [0x73587460] cursor moved to 166,000000, 266,000000
     [Demo] 7,208: Window [0x73587460] cursor moved to 161,000000, 266,000000
     [Demo] 7,209: Window [0x73587460] cursor moved to 156,000000, 266,000000
     [Demo] 7,224: Window [0x73587460] cursor moved to 153,000000, 265,000000
     [Demo] 7,226: Window [0x73587460] cursor moved to 149,000000, 263,000000
     [Demo] 7,243: Window [0x73587460] cursor moved to 144,000000, 263,000000
     [Demo] 7,244: Window [0x73587460] cursor moved to 142,000000, 262,000000
     [Demo] 7,258: Window [0x73587460] cursor moved to 138,000000, 261,000000
     [Demo] 7,259: Window [0x73587460] cursor moved to 134,000000, 260,000000
     [Demo] 7,260: Window [0x73587460] cursor moved to 130,000000, 260,000000
     [Demo] 7,284: Window [0x73587460] cursor moved to 126,000000, 260,000000
     [Demo] 7,294: Window [0x73587460] cursor moved to 125,000000, 260,000000
     [Demo] 7,295: Window [0x73587460] cursor moved to 124,000000, 260,000000
     [Demo] 7,296: Window [0x73587460] cursor moved to 124,000000, 259,000000
     [Demo] 7,312: Window [0x73587460] cursor moved to 124,000000, 258,000000
     [Demo] 7,324: Window [0x73587460] cursor moved to 127,000000, 256,000000
     [Demo] 7,326: Window [0x73587460] cursor moved to 133,000000, 253,000000
     [Demo] 7,341: Window [0x73587460] cursor moved to 141,000000, 250,000000
     [Demo] 7,342: Window [0x73587460] cursor moved to 152,000000, 248,000000
     [Demo] 7,358: Window [0x73587460] cursor moved to 167,000000, 244,000000
     [Demo] 7,374: Window [0x73587460] cursor moved to 179,000000, 243,000000
     [Demo] 7,376: Window [0x73587460] cursor moved to 188,000000, 241,000000
     [Demo] 7,394: Window [0x73587460] cursor moved to 201,000000, 240,000000
     [Demo] 7,395: Window [0x73587460] cursor moved to 212,000000, 240,000000
     [Demo] 7,408: Window [0x73587460] cursor moved to 221,000000, 238,000000
     [Demo] 7,409: Window [0x73587460] cursor moved to 229,000000, 238,000000
     [Demo] 7,424: Window [0x73587460] cursor moved to 239,000000, 237,000000
     [Demo] 7,426: Window [0x73587460] cursor moved to 250,000000, 234,000000
     [Demo] 7,441: Window [0x73587460] cursor moved to 261,000000, 229,000000
     [Demo] 7,442: Window [0x73587460] cursor moved to 275,000000, 224,000000
     [Demo] 7,458: Window [0x73587460] cursor moved to 298,000000, 214,000000
     [Demo] 7,459: Window [0x73587460] cursor moved to 318,000000, 204,000000
     [Demo] 7,474: Window [0x73587460] cursor moved to 342,000000, 192,000000
     [Demo] 7,476: Window [0x73587460] cursor moved to 366,000000, 180,000000
     [Demo] 7,493: Window [0x73587460] cursor moved to 390,000000, 172,000000
     [Demo] 7,494: Window [0x73587460] cursor moved to 412,000000, 162,000000
     [Demo] 7,508: Window [0x73587460] cursor moved to 432,000000, 152,000000
     [Demo] 7,509: Window [0x73587460] cursor moved to 448,000000, 140,000000
     [Demo] 7,510: Window [0x73587460] cursor moved to 459,000000, 129,000000
     [Demo] 7,524: Window [0x73587460] cursor moved to 469,000000, 119,000000
     [Demo] 7,526: Window [0x73587460] cursor moved to 480,000000, 106,000000
     [Demo] 7,542: Window [0x73587460] cursor moved to 493,000000, 91,000000
     [Demo] 7,544: Window [0x73587460] cursor moved to 505,000000, 80,000000
     [Demo] 7,558: Window [0x73587460] cursor moved to 520,000000, 67,000000
     [Demo] 7,559: Window [0x73587460] cursor moved to 535,000000, 55,000000
     [Demo] 7,574: Window [0x73587460] cursor moved to 549,000000, 41,000000
     [Demo] 7,576: Window [0x73587460] cursor moved to 559,000000, 34,000000
     [Demo] 7,597: Window [0x73587460] cursor moved to 569,000000, 27,000000
     [Demo] 7,598: Window [0x73587460] cursor moved to 575,000000, 21,000000
     [Demo] 7,608: Window [0x73587460] cursor moved to 577,000000, 17,000000
     [Demo] 7,609: Window [0x73587460] cursor moved to 578,000000, 14,000000
     [Demo] 7,609: Window [0x73587460] cursor moved to 579,000000, 12,000000
     [Demo] 7,624: Window [0x73587460] cursor moved to 579,000000, 10,000000
     [Demo] 7,641: Window [0x73587460] cursor moved to 579,000000, 7,000000
     [Demo] 7,642: Window [0x73587460] cursor moved to 580,000000, 6,000000
     [Demo] 7,658: Window [0x73587460] cursor moved to 580,000000, 5,000000
     [Demo] 7,660: Window [0x73587460] cursor moved to 582,000000, 3,000000
     [Demo] 7,674: Window [0x73587460] cursor moved to 585,000000, 0,000000
     [Demo] 7,676: Window [0x73587460] cursor moved to 587,000000, 0,000000
     [Demo] 7,677: Window [0x73587460] cursor left
     [Demo] 8,181: Window [0x73587460] closed
     [Demo] Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.lwjgl.system.libffi.FFIClosure.user_data()" because the return value of "org.lwjgl.system.Callback$ClosureRegistry.get(long)" is null
     [Demo] 	at org.lwjgl.system.Callback.get(Callback.java:190)
     [Demo] 	at org.lwjgl.glfw.GLFWErrorCallback.create(GLFWErrorCallback.java:40)
     [Demo] 	at org.lwjgl.glfw.GLFWErrorCallback.createSafe(GLFWErrorCallback.java:49)
     [Demo] 	at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:1288)
     [Demo] 	at org.lwjgl.demo.glfw.Events.main(Events.java:54)

BUILD FAILED
/home/pi/Downloads/lwjgl3/build.xml:888: Java returned: 1

Total time: 15 seconds

The same exception occurs after the window is closed, when calling glfwSetErrorCallback.

@Spasi
Copy link
Member

Spasi commented Jan 29, 2022

Thank you @mindstorm38, this looks like a bug indeed.

I'm afraid I don't have access to my RPi atm and won't be able to debug this properly for a couple of months at least.

I went through all the relevant code, as well as the CI build for libffi, couldn't find anything that would justify this behavior. It also looks kind of random? For example, the NPE happens on glfwFreeCallbacks in the Gears demo, but on glfwSetErrorCallback in the Events demo, even though glfwFreeCallbacks has already been called there too. Could you verify this? Do you always get the exact same stacktrace on every run?

Try adding System.err.println(executableAddress); before line 176 and System.err.println(functionPointer); before line 209. Also change line 209 to FFIClosure closure = CLOSURE_REGISTRY.remove(functionPointer); (that's a bug in the current implementation, but it shouldn't affect this issue). Could you please post some output with those two print statements?

Finally, try running the tests/demos with -Dorg.lwjgl.system.allocator=system. Any changes?

@mindstorm38
Copy link
Author

I will test this later, thank you :)

@mindstorm38
Copy link
Author

Without changing anything but -Dorg.lwjgl.system.allocator=system, it doesn't change anything to the output.

Without system allocator:

Gears demo:

     [Demo] create: 3068719068
     [Demo] create: 3068719048
     [Demo] create: 3068719028
     [Demo] create: 3068719008
     [Demo] create: 3068718988
     [Demo] create: 3068718968
     [Demo] create: 3068718948
     [Demo] create: 3068718928
     [Demo] GL_VENDOR: Broadcom
     [Demo] GL_RENDERER: V3D 4.2
     [Demo] GL_VERSION: 2.1 Mesa 19.3.2
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_FRAGMENT shader: 12 inst, 4 threads, 0 loops, 0 uniforms, 4 max-temps, 0:0 spills:fills, 0 sfu-stalls, 12 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_VERTEX shader: 24 inst, 4 threads, 0 loops, 5 uniforms, 6 max-temps, 0:0 spills:fills, 0 sfu-stalls, 24 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_COORD shader: 19 inst, 4 threads, 0 loops, 2 uniforms, 5 max-temps, 0:0 spills:fills, 0 sfu-stalls, 19 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_FRAGMENT shader: 9 inst, 4 threads, 0 loops, 4 uniforms, 5 max-temps, 0:0 spills:fills, 0 sfu-stalls, 9 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_VERTEX shader: 72 inst, 4 threads, 0 loops, 32 uniforms, 11 max-temps, 0:0 spills:fills, 0 sfu-stalls, 72 inst-and-stalls
     [Demo] [LWJGL] OpenGL debug message
     [Demo] 	ID: 0x2
     [Demo] 	Source: SHADER COMPILER
     [Demo] 	Type: OTHER
     [Demo] 	Severity: NOTIFICATION
     [Demo] 	Message: MESA_SHADER_COORD shader: 41 inst, 4 threads, 0 loops, 18 uniforms, 10 max-temps, 0:0 spills:fills, 0 sfu-stalls, 41 inst-and-stalls
     [Demo] 46 fps
     [Demo] 60 fps
     [Demo] free: 3068718928
     [Demo] free: -1226248348
     [Demo] java.lang.NullPointerException: Cannot invoke "org.lwjgl.system.libffi.FFIClosure.user_data()" because "closure" is null
     [Demo] 	at org.lwjgl.system.Callback.free(Callback.java:211)
     [Demo] 	at org.lwjgl.glfw.Callbacks.glfwFreeCallbacks(Callbacks.java:55)
     [Demo] 	at org.lwjgl.demo.glfw.Gears.destroy(Gears.java:230)
     [Demo] 	at org.lwjgl.demo.glfw.Gears.run(Gears.java:47)
     [Demo] 	at org.lwjgl.demo.glfw.Gears.main(Gears.java:37)

Events demo:

     [Demo] create: 3068989404
     [Demo] ---- [ Error callback test ] ----
     [Demo] [LWJGL] GLFW_NOT_INITIALIZED error
     [Demo] 	Description : The GLFW library is not initialized
     [Demo] 	Stacktrace  :
     [Demo] 		org.lwjgl.glfw.GLFW.glfwDefaultWindowHints(GLFW.java:1857)
     [Demo] 		org.lwjgl.demo.glfw.Events.main(Events.java:40)
     [Demo] ---- [ Error callback done ] ----
     [Demo] GLFW initialized
     [Demo] 
     [Demo] Monitor 0:
     [Demo] ----------
     [Demo] 	Name: HDMI-1 (primary)
     [Demo] 	Current mode    : 1920 x 1080 @ 60 Hz (16:9, R8G8B8)
     [Demo] 	Content scale   : 1,000000 x 1,000000
     [Demo] 	Physical size   : 531mm x 299mm (24", 92 ppi)
     [Demo] 	Virtual position: 0, 0
     [Demo] 
     [Demo] Window opened:
     [Demo] --------------
     [Demo] 	Size: 640 x 480
     [Demo] 	Frame size: 2, 30, 0, 0
     [Demo] 	Content scale: 1,000000 x 1,000000
     [Demo] 	Framebuffer size: 640 x 480
     [Demo] 	Position: 0, 0
     [Demo] 
     [Demo] create: 3068989384
     [Demo] create: 3068989364
     [Demo] create: 3068989344
     [Demo] create: 3068989324
     [Demo] create: 3068989304
     [Demo] create: 3068989284
     [Demo] create: 3068989264
     [Demo] create: 3068989244
     [Demo] create: 3068989224
     [Demo] create: 3068989204
     [Demo] create: 3068989184
     [Demo] create: 3068989164
     [Demo] create: 3068989144
     [Demo] create: 3068989124
     [Demo] create: 3068989104
     [Demo] create: 3068989084
     [Demo] create: 3068989064
     [Demo] create: 3068989044
     [Demo] create: 3068989024
     [Demo] 1,225: Window [0x735874B8] moved to 2, 30
     [Demo] 1,244: Window [0x735874B8] moved to 2, 66
     [Demo] 1,244: Window [0x735874B8] refreshed
     [Demo] 1,245: Window [0x735874B8] gained focus
     [Demo] 5,980: Window [0x735874B8] cursor entered
     [Demo] 5,982: Window [0x735874B8] cursor moved to 639,000000, 17,000000
     [Demo] 5,998: Window [0x735874B8] cursor moved to 637,000000, 12,000000
     [Demo] 6,001: Window [0x735874B8] cursor moved to 634,000000, 6,000000
     [Demo] 6,005: Window [0x735874B8] cursor left
     [Demo] free: -1225977952
     [Demo] 7,634: Window [0x735874B8] closed
     [Demo] Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.lwjgl.system.libffi.FFIClosure.user_data()" because the return value of "org.lwjgl.system.Callback$ClosureRegistry.get(long)" is null
     [Demo] 	at org.lwjgl.system.Callback.get(Callback.java:190)
     [Demo] 	at org.lwjgl.glfw.GLFWErrorCallback.create(GLFWErrorCallback.java:40)
     [Demo] 	at org.lwjgl.glfw.GLFWErrorCallback.createSafe(GLFWErrorCallback.java:49)
     [Demo] 	at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:1288)
     [Demo] 	at org.lwjgl.demo.glfw.Events.main(Events.java:54)

@Spasi
Copy link
Member

Spasi commented Feb 6, 2022

I've found the bug, will be fixed in the next snapshot (3.3.1 build 5).

3.3.1 will also have to be released ahead of schedule, because LWJGL is currently broken on Windows x86 and Linux ARM32.

@Spasi Spasi closed this as completed in 0db2149 Feb 7, 2022
@Spasi
Copy link
Member

Spasi commented Feb 7, 2022

Thanks @mindstorm38!

fayer3 pushed a commit to fayer3/lwjgl3 that referenced this issue Jul 14, 2023
This fixes pointer casts on 32-bit architectures. Previously, addresses
that happened to be greater than 2GB on x86/arm32 would overflow when
cast to intptr_t and, via the cast to jlong, propagate as negative
values to Java code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants