LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.67k stars 631 forks source link

Support JNI_VERSION_19 fixing crash with Java 19 EA when preview features are enabled. #799

Closed modmuss50 closed 1 year ago

modmuss50 commented 1 year ago

JEP 425 (Project Loom) added the JNI function IsVirtualThread. This PR updates ThreadLocalUtil to support the addion of this new function and JNI version.

JDK change: https://github.com/openjdk/jdk/commit/53bf1bfdabb79b37afedd09051d057f9eea620f2 JDK issue: https://bugs.openjdk.org/browse/JDK-8286176

This change fixes a crash when running on the latest Java 19 EA build with preview features enabled. This was noticed when testing with Minecraft 1.19.2 on Windows + Java 19 EA with preview features enabled.

Please let me know if any further information or testing is required 👍

Spasi commented 1 year ago

Thank you @modmuss50!

gudenau commented 1 year ago

@Spasi Would it be possible to change the implementation to scan for a null pointer at the end of the structure? Unless the structure grows to be on an allocation border I would think that scanning would be more robust.

Spasi commented 1 year ago

@gudenau Hey, I don't think that would be a reliable fix.

In any case, new JNI functions are rare, it's only happened twice in LWJGL3's lifetime (Java 9 and Java 19). I'll add a Configuration override, if it happens again, a workaround without updating LWJGL will be available.