glfw: Window hints get reverted to default after window creation and cannot be set #201

Closed
opened 2022-03-31 17:48:54 +00:00 by prime31 · 4 comments
prime31 commented 2022-03-31 17:48:54 +00:00 (Migrated from github.com)

Once a window is created the GLFW wrapper resets all the hints to default. There is no public API available to set a hint so now we are stuck in a state where we can't work with hints at all. The README states that hint is a public method but it is not.

Methods, e.g. my_window.hint(...) instead of glfwWindowHint(my_window, ...)

Possible fixes:

  • make window.hint public
  • dont keep resetting default hints after windows are created
  • expose as public c so that we can override and call raw GLFW methods ourselves when necessary
Once a window is created the GLFW wrapper resets all the hints to default. There is no public API available to set a hint so now we are stuck in a state where we can't work with hints at all. The README states that `hint` is a public method but it is not. > Methods, e.g. `my_window.hint(...)` instead of `glfwWindowHint(my_window, ...)` Possible fixes: - make `window.hint` public - dont keep resetting default hints after windows are created - expose as public `c` so that we can override and call raw GLFW methods ourselves when necessary
emidoots commented 2022-03-31 19:55:52 +00:00 (Migrated from github.com)

You're correct the README is out of date. The idea is that you pass a struct to createWindow with the hints, it sets them for you, and resets to defaults after the fact.

Is this approach problematic for interior with other C code, or are you having trouble finding the struct where window hints get passed in?

You're correct the README is out of date. The idea is that you pass a struct to createWindow with the hints, it sets them for you, and resets to defaults after the fact. Is this approach problematic for interior with other C code, or are you having trouble finding the struct where window hints get passed in?
prime31 commented 2022-03-31 22:29:19 +00:00 (Migrated from github.com)

The issue here is the resetting of the defaults. Once I set a hint I wouldn't expect it to get unset without me specifically requesting it. I came across the issue when adding Dear ImGui to my project. I set some hints and then Dear ImGui would create a window with glfwCreateWindowSurface and it would fail assertions in vulkan.c due to the GLFW_CLIENT_API hint being reset:

    if (window->context.client != GLFW_NO_API)
    {
        _glfwInputError(GLFW_INVALID_VALUE,
                        "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API");
        return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;
    }
    ```
The issue here is the resetting of the defaults. Once I set a hint I wouldn't expect it to get unset without me specifically requesting it. I came across the issue when adding Dear ImGui to my project. I set some hints and then Dear ImGui would create a window with `glfwCreateWindowSurface` and it would fail assertions in `vulkan.c` due to the `GLFW_CLIENT_API` hint being reset: ```c if (window->context.client != GLFW_NO_API) { _glfwInputError(GLFW_INVALID_VALUE, "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API"); return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; } ```
emidoots commented 2022-04-01 01:41:40 +00:00 (Migrated from github.com)

Aha! Okay, now I understand. So glfwCreateWindowSurface internally relies on window hints. I did not realize this.

The idea with hints being passed as a struct to glfw.Window.create is that it becomes stateless: you pass in the desired state, we ensure it's that, then we wipe the state away afterwards (just because that seemed clean)

But I see now that, actually, you sometimes need those window hints to be retained for longer periods of time.

In this case, I think that your suggestion of "don't reset hints after window creation" sounds good to me (in addition to exposing a method to reset them) - this way we keep the stateless aspect of glfw.Window.create on it's own, and just leave the window hints in a "dirty" state.

Aha! Okay, now I understand. So `glfwCreateWindowSurface` internally relies on window hints. I did not realize this. The idea with hints being passed as a struct to `glfw.Window.create` is that it becomes stateless: you pass in the desired state, we ensure it's that, then we wipe the state away afterwards (just because that seemed clean) But I see now that, actually, you sometimes need those window hints to be retained for longer periods of time. In this case, I think that your suggestion of "don't reset hints after window creation" sounds good to me (in addition to exposing a method to reset them) - this way we keep the stateless aspect of `glfw.Window.create` on it's own, and just leave the window hints in a "dirty" state.
prime31 commented 2022-04-01 04:55:47 +00:00 (Migrated from github.com)

That sounds perfecto!

That sounds perfecto!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#201
No description provided.