openglcrashlwjglmacos-high-sierraforward-compatibility

LWJGL 3.1.6 OpenGL 4.1 crash on macOS High Sierra


I have a slightly modified version of the sample code found on the main LWJGL page. It works but it uses legacy OpenGL version 2.1. If I attempt to use the forward-compatible context described in GLFW doc, the version used is 4.1 (no matter what major/minor I hint), the window is created, but it crashes on the first call to glPushMatrix().

Forward compatibility enabled like so:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Some info I print in the console:

LWJGL 3.1.6 build 14
OS name Mac OS X
OS version 10.13.4
OpenGL version 4.1 ATI-1.66.31

Logging:

[LWJGL] A function that is not available in the current context was called.
Problematic frame:
C  [liblwjgl.dylib+0x1c494]

From here I don't know what to look for. Should this code be working? Or am I missing some ceremony? Many resources are outdated, making it harder to figure things out.


Solution

  • glPushMatrix is a function for not Core Profile context, but for OpenGL < 3.2.

    If you want to use it (and other pre-core features) you need a Compatibility context, not a Forward compatible one, not a Core profile either.

    The GLFW hints should be like these, without asking for a Core Profile.

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
    

    Likely the driver will give the highest available version, but with all of old features too.