ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.35k stars 10.33k forks source link

When switching from master to docking branch, glfw gives me an error message each time ImGui_ImplGlfw_NewFrame() is called #3451

Closed krismale closed 3 years ago

krismale commented 4 years ago

Version: v1.79 Branch: docking

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp Compiler: MSVC Operating System: Windows 10

Hi! I'm struggling a bit with finding a solution to this error message that gets thrown after I switched from your master branch to the docking branch:

[ERROR]: 65539, Invalid window attribute 0x0002000D

The error message shows up each time _ImGui_ImplGlfwNewFrame() gets called. After doing some debugging, it appears that it's coming from line 362 in imgui_impl_glfw.cpp: _glfwSetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH, window_noinput);. I'm quite new to ImGui so I'm not really sure why this is happening. The docking feature and multi-viewport works perfectly as far as I know right now, but I'm afraid that I might run into some issues down the road. On top of that, my log gets filled up with this error message, so it's hard to notice anything else going on.

Here's my code implementing ImGui:

int ImGuiInit(GLFWwindow* window)
{
    // Setup Dear ImGui context
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();

    ImGuiIO& io = ImGui::GetIO();
    io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;       // Enable Keyboard Controls
    io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;           // Enable Docking
    io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;         // Enable Multi-Viewport / Platform Windows

    // Setup Dear ImGui style
    ImGui::StyleColorsDark();

    // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
    ImGuiStyle& style = ImGui::GetStyle();
    if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
    {
        style.WindowRounding = 0.0f;
        style.Colors[ImGuiCol_WindowBg].w = 1.0f;
    }

    // Setup Platform/Renderer bindings
    if (!ImGui_ImplGlfw_InitForOpenGL(window, true)) {
        Log("[ERROR]: ImGui init for GLFW failed.");
        return(-1);
    }
    if (!ImGui_ImplOpenGL3_Init("#version 410")) {
        Log("[ERROR]: ImGui init for OpenGL failed.");
        return(-1);
    }

    return 0;
}

void ImGuiInput()
{
    // feed inputs to dear imgui, start new frame
    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();
}

void RenderImGui(GLFWwindow* window)
{
    // render your GUI
    ImGui::Begin("Demo window");
    ImGui::Button("Hello!");
    ImGui::End();
    static bool show = true;
    ImGui::ShowDemoWindow(&show);

    // Render dear imgui into screen
    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

    ImGuiIO& io = ImGui::GetIO();
    if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
        GLFWwindow* backup_current_context = glfwGetCurrentContext();
        ImGui::UpdatePlatformWindows();
        ImGui::RenderPlatformWindowsDefault();
        glfwMakeContextCurrent(backup_current_context);
    }
}

Here's how glfw is initialized:

static int WindowInit()
{
    if(!glfwInit())
    {
        Log("[ERROR]: glfwInit failed.");
        return(-1);
    }

    // https://www.glfw.org/docs/latest/window.html#window_hints
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);

#ifdef __APPLE__
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif

    MainWindow = glfwCreateWindow(WINDOW_WITDH, WINDOW_HEIGHT, WINDOW_TITLE, nullptr, nullptr);

    if(!MainWindow)
    {
        Log("[ERROR]: GLFW Failed to create window, terminating!");
        return(-1);
    }

    glfwSetInputMode(MainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);

    glfwMakeContextCurrent(MainWindow);

    glfwSwapInterval(1);

    glfwSetMouseButtonCallback(MainWindow, MouseClickCallback);
    glfwSetCharCallback(MainWindow, CharCallback);
    glfwSetCursorPosCallback(MainWindow, MouseMoveCallback);
    glfwSetErrorCallback(ErrorCallback);
    glfwSetJoystickCallback(JoystickCallback);
    glfwSetKeyCallback(MainWindow, KeyCallback);
    glfwSetScrollCallback(MainWindow, ScrollCallback);
    glfwSetWindowSizeCallback(MainWindow, WinResizeCallback);
    glfwSetInputMode(MainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
    return(0);
}

Hope this makes sense, please help!

rokups commented 4 years ago

GLFW_MOUSE_PASSTHROUGH use is guarded against in older GLFW versions that do not support it. Is it possible that you somehow built your application against newer headers while running example application with older GLFW dll (pre-3.4)?

krismale commented 4 years ago

No we did have GLFW 3.4 and the latest version of ImGui. We did some more testing now and found out that the error didn't show up if we downgraded to GLFW 3.3. Although it would be ideal to use the latest version of GLFW, and I guess that the GLFW_MOUSE_PASSTHROUGH would be useful to have as a feature. There's probably also a couple of other things in 3.4 that might be useful for us.

rokups commented 4 years ago

Seems to me like a GLFW bug then

ocornut commented 4 years ago

I think you'll want to investigate and step in a debugger to see what GLFW is doing there.

ocornut commented 3 years ago

Any update on this? I am finding it hard to explain this other than a user error (e.g. some unexpected wrong version loaded dynamically etc.) or an odd GLFW bug,

krismale commented 3 years ago

We decided to stick with v3.3 throughout the project and disable the viewport features. Everything worked fine with the docking so we decided to just keep that. Never really found out what the issue was though, but it’s most likely a bug in glfw 3.4 as @rokups mentioned

Micovec commented 2 years ago

Got the very same error at exactly the same line (at different number due to project growing) with glfw v3.3.8.

Specs: Windows 10 Visual Studio 4.8.04084

I resolved it by replacing it with the same library!

I was copying git repository with glfw static library inside it to another folder and this error showed on the first solution project rebuild. It seems like there was some kind of bug inside library? Or perhaps it was Visual Studio doing its stuff.

mcduncan-chen commented 1 year ago

I met the same problem, it shows repeating "Error: Invalid window attribute 0x0002000D" after I switched to ImGui docking branch.

System: Windows 10 pro MSYS2 64-bit $ cat /proc/version MINGW64_NT-10.0-19044 version 3.3.6-341.x86_64 (runneradmin@fv-az283-774) (gcc version 11.3.0 (GCC) ) 2022-09-20 22:07 UTC $ pacman -Q mingw-w64-x86_64-glfw mingw-w64-x86_64-glfw 3.3.8-2

Backtrace the glfw code, found that the latest glfw source can handle 0x0002000D attribute, which is GLFW_MOUSE_PASSTHROUGH, but 3.3.8 release didn't.

git clone the latest glfw source, and rebuild glfw with following commands cd path/to/glfw mkdir build cd build cmake -S ../ -B . -G "MSYS Makefiles" -D BUILD_SHARED_LIBS=ON make

The library libglfw3dll.a and dll file glfw3.dll will be compiled under path/to/glfw/build/src folder. Recompile code, and run with the newly genereated glfw3.dll, it works like a charm, problem resolved.