Search code examples
javamultithreadingmacosopengllwjgl

LWJGL Errors - Failed to locate address for GL function glVertexArrayVertexAttribDivisorEXT


I have scoured the internet far and wide looking for answers to this problem. I realize that LWJGL3 is still in the works but no one else but me seems to be having this problem. So it goes like this, I have a Mac and a PC and I like to develop in Java and LWJGL because of how it supposed to be cross platform. However, the app runs just fine on the PC but when I run it on my Mac with debugging on I get this in the console:

[LWJGL] Version 3.0.0b build 35 | Mac OS X | x86_64
[LWJGL] Loaded library from java.library.path: lwjgl
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] Loaded native library: lib/libjemalloc.dylib
[LWJGL] MemoryUtil allocator: JEmallocAllocator
[LWJGL] Loaded native library: lib/libglfw.dylib
[LWJGL] Loaded native library bundle: /System/Library/Frameworks/OpenGL.framework
[LWJGL] Failed to locate address for GL function glVertexArrayVertexAttribDivisorEXT

I believe the "Failed to locate..." happens during the GL.createCapabilities() call. As a result I think this makes the OpenGL initialization fail and just create a blank screen because that seems to be whats happening to me.

Here is the actual code:

        glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));

        if (glfwInit() != GL11.GL_TRUE)
            throw new IllegalStateException("Unable to initialize GLFW");

        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

        ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        WIDTH = GLFWvidmode.width(vidmode);
        HEIGHT = GLFWvidmode.height(vidmode);
        RENDER_RATIO = (float) WIDTH / 1920.0f; // Scales all the rendering by a constant

        window = glfwCreateWindow(WIDTH, HEIGHT, "Game", glfwGetPrimaryMonitor(), NULL);
        if (window == NULL)
            throw new RuntimeException("Failed to create the GLFW window");

        // GLFW Callbacks
        glfwSetKeyCallback(window, keyCallback = new Keyboard());
        glfwSetCursorPosCallback(window, cursorPosCallback = new Mouse.CursorPos());
        glfwSetMouseButtonCallback(window, mouseButtonCallback = new Mouse.MouseButton());
        glfwSetScrollCallback(window, scrollCallback = new Mouse.Scroll());

        glfwMakeContextCurrent(window);
        glfwSwapInterval(1);
        glfwShowWindow(window);

        // Initialize OpenGL
        GL.createCapabilities(); //New for LWJGL 3.0.0b
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glClearColor(1f, 0f, 0f, 1.0f); //Red background

The window initializes but I would guess that the OpenGL context does not because the window is black when I set the background to red. Before that I was getting "not started on main thread" exceptions but they were fixed by adding -XstartOnFirstThread to my VM arguments. This is a multi-threaded game loop but I made sure to keep the rendering on the main thread and the updating on a new thread, however it doesn't even get that far because it's not initialing OpenGL properly. Also it does run but it only locks up when it get to the rendering calls, causing the rendering loop to freeze. Here are my VM arguments:

-XstartOnFirstThread -Djava.library.path=lib/ -Dorg.lwjgl.util.Debug=true

I really have had trouble finding any other posts with the same problem. I found some really old posts that said they were bugs so maybe this is as well. It could be something simple and I'm just being dumb, but if it helps I have included the entire class in the link below. Thanks in advance.

Full class: http://pastebin.com/eZ1qXPsd


Solution

  • This is a function that was added to the ARB_instanced_arrays extension after it had already been implemented in OpenGL drivers. That means that some drivers may expose the extension even if that particular function is missing, so it's been made optional in LWJGL. This is from the extension spec:

    7) How should EXT_direct_state_access interact with this extension?

    Resolved: Add glVertexArrayVertexAttribDivisorEXT selector-free
    vertex array object command and glGetVertexArrayIntegeri_vEXT query must accept VERTEX_ATTRIB_ARRAY_DIVISOR_ARB to return the vertex array object's vertex attrib array divisor state.

    The DSA interaction was added July 2013. If implementations
    respond to a wglGetProcAddress, etc. query for
    "glVertexArrayVertexAttribDivisorEXT" with a NULL pointer, the DSA functionality is not available.

    The message:

    Failed to locate address for GL function glVertexArrayVertexAttribDivisorEXT

    is a simple warning in debug mode and can safely be ignored. If you need to use that function, you can check if it is available using the following code:

    // get the extension instance for the current context
    ARBInstancedArrays ext = ARBInstancedArrays.getInstance(); 
    if ( ext.VertexArrayVertexAttribDivisorEXT != NULL ) {
        // the function is available
    }