Posix Thread Local Storage (TLS) error when making context current

Hi! I have been trying to wrap a small offscreen rendering app with pybind. I’ve got all that set up and working, but when I try to initialize and make a GLFW window current, I get this error:

python3: ../libs/glfw/src/posix_thread.c:64: _glfwPlatformGetTls: Assertion `tls->posix.allocated == GLFW_TRUE' failed.
Aborted (core dumped)

Here is where the code fails:

    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE);
    state.gl_main_context = glfwCreateWindow(640, 480, "MyApp", 0, 0);

    glfwMakeContextCurrent(state.gl_main_context); //<--- fails on this line

I have checked that the app works as expected when not wrapped with pybind, so I guess I’m looking for any insight into what might trigger this error or any known gotchas when wrapping with pybind.

Can you check result of glfwInit() - does it return GLFW_TRUE? What about glfwCreateWindow() return? is it non-NULL?

In case any of these functions fail, see the glfw docs on error handling to get more detailed error code & description: https://www.glfw.org/docs/latest/intro_guide.html#error_handling

Hey thanks! inded glfwInit failed and that led me quickly to the solution. I had not configured the DISPLAY=:0 env variable before running (I’m doing this on a headless server).