Foryxled_Dev
Foryxled_Dev

Reputation: 37

Unsupported JNI version detected in LWJGL

So I tried using glfw and opengl for game development in java (for some reason) and recently I start getting an lwjgl error that I still don't know how to fix it

here is my source code:

import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;

import java.nio.*;
import java.util.Objects;

import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;

public class main {

    private long window;

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

        init();
        loop();

        glfwFreeCallbacks(window);
        glfwDestroyWindow(window);

        glfwTerminate();
        Objects.requireNonNull(glfwSetErrorCallback(null)).free();
    }

    private void init() {
        GLFWErrorCallback.createPrint(System.err).set();

        if ( !glfwInit() ) {
            throw new IllegalStateException("Unable to initialize GLFW");
        }

        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
        glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);

        int windowWidth = 640;
        int windowHeight = 480;

        window = glfwCreateWindow(windowWidth, windowHeight, "Game", GLFW_RESIZABLE, NULL);

        if ( window == NULL )
            throw new RuntimeException("Failed to create the GLFW window");

        glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
            if ( key == GLFW_KEY_ESCAPE && action == GLFW_PRESS )
                glfwSetWindowShouldClose(window, true);
        });

        try ( MemoryStack stack = stackPush() ) {
            IntBuffer pWidth = stack.mallocInt(1); // int*
            IntBuffer pHeight = stack.mallocInt(1); // int*

            glfwGetWindowSize(window, pWidth, pHeight);

            GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
            assert vidmode != null;
            glfwSetWindowPos(
                    window,
                    (vidmode.width() - pWidth.get(0)) / 2,
                    (vidmode.height() - pHeight.get(0)) / 2
            );
        }

        glfwMakeContextCurrent(window);
        glfwSwapInterval(1);

        glfwShowWindow(window);
    }

    private void loop() {
        GL.createCapabilities();

        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        while ( !glfwWindowShouldClose(window) ) {
            glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            glBegin(GL_POLYGON);
            glEnd();

            glfwSwapBuffers(window);

            glfwPollEvents();
        }
    }

    public static void main(String[] args) {
        new main().run();
    }

}

(If there are improvement I could use in the code the pls tell me)

And here is the error:

Hello LWJGL 3.3.1 build 7!
[LWJGL] [ThreadLocalUtil] Unsupported JNI version detected, this may result in a crash. Please inform LWJGL developers.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc3c5aba56, pid=6740, tid=14624
#
# JRE version: Java(TM) SE Runtime Environment (19.0.1+10) (build 19.0.1+10-21)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (19.0.1+10-21, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# C  [ntdll.dll+0x3ba56]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\IntelliJ IDEA Projects\Game Project\hs_err_pid6740.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 1

IDE: IntelliJ IDEA community

LWJGL 3.3.1 build 7

I tried changing JDK version, changing SDK version, redownloading LWJGL libraries, editing source codes

(None of it worked)

Upvotes: 1

Views: 3073

Answers (2)

Mac Mcleod
Mac Mcleod

Reputation: 1

If doing minecraft modding, this occurs when you fail to update the forge version number in the gradlew.properties file correctly.

For example, if you are on forge 52 but your property file says 46, this error will occur.

Upvotes: 0

squid233
squid233

Reputation: 166

The 4th parameter in glfwCreateWindow accepts a pointer of monitor.

Simply replace it with NULL.

window = glfwCreateWindow(windowWidth, windowHeight, "Game", NULL, NULL);

Upvotes: 0

Related Questions