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

**URL:** <https://discourse.glfw.org/t/posix-thread-local-storage-tls-error-when-making-context-current/2034>\
**Category:** dev\
**Created:** [April 7, 2022, 11:31pm UTC](https://discourse.glfw.org/t/posix-thread-local-storage-tls-error-when-making-context-current/2034 "2022-04-07T23:31:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danhambleton](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/danhambleton/32/614_2.png) [@danhambleton](https://discourse.glfw.org/u/danhambleton)\
**Post date:** [April 7, 2022, 11:31pm UTC](https://discourse.glfw.org/t/posix-thread-local-storage-tls-error-when-making-context-current/2034/1 "2022-04-07T23:31:46Z")

</div>

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:

```auto
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:

```auto
    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.

---

<div class="post-metadata">

**Author:** ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)\
**Post date:** [April 8, 2022, 3:54am UTC](https://discourse.glfw.org/t/posix-thread-local-storage-tls-error-when-making-context-current/2034/2 "2022-04-08T03:54:35Z")

</div>

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](https://www.glfw.org/docs/latest/intro_guide.html#error_handling)

---

<div class="post-metadata">

**Author:** ![danhambleton](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/danhambleton/32/614_2.png) [@danhambleton](https://discourse.glfw.org/u/danhambleton)\
**Post date:** [April 8, 2022, 3:43pm UTC](https://discourse.glfw.org/t/posix-thread-local-storage-tls-error-when-making-context-current/2034/3 "2022-04-08T15:43:48Z")

</div>

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).
