SFML / imgui-sfml

Dear ImGui backend for use with SFML
MIT License
1.13k stars 169 forks source link

BadCursor error on shutdown #204

Open naftali100 opened 2 years ago

naftali100 commented 2 years ago
X Error of failed request:  BadCursor (invalid Cursor parameter)
  Major opcode of failed request:  2 (X_ChangeWindowAttributes)
  Resource id in failed request:  0x7000017
  Serial number of failed request:  525
  Current serial number in output stream:  531

getting this error when mouse click cause shutdown (clicking imgui button that cause the main loop to break), and sfml window was not closed (easy to fix.. just check if the window is open and close if true...), And call sf::imgui::shutdown().

I thought it worth sharing if someone will get the same error... it took me about a hour to find the problem...

eliasdaler commented 2 years ago

Hello Please provide a small reproducible example - hard to tell what you mean otherwise, sorry.

oprypin commented 2 years ago

I tried to guess what is meant here, and even throw in an extra cursor manipulation, but I don't observe any such error.

diff --git a/examples/minimal/main.cpp b/examples/minimal/main.cpp
index 2c19abd08..d30ae607e 100644
--- a/examples/minimal/main.cpp
+++ b/examples/minimal/main.cpp
@@ -31,7 +31,11 @@ int main() {
         ImGui::ShowDemoWindow();

         ImGui::Begin("Hello, world!");
-        ImGui::Button("Look at this pretty button");
+        if (ImGui::Button("Exit")) {
+            window.close();
+        }
+        if (ImGui::IsItemHovered())
+            ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
         ImGui::End();

         window.clear();

c++ -I. -I../cimgui/imgui examples/minimal/main.cpp imgui-SFML.cpp ../cimgui/imgui/{imgui_demo.cpp,imgui_widgets.cpp,imgui.cpp,imgui_draw.cpp,imgui_tables.cpp} -lsfml-graphics -lsfml-window -lsfml-system -lGL && ./a.out

Does not reproduce when I click the button

naftali100 commented 2 years ago

i'm sorry for the delay. i forgot about it... here is a minimal example

int main(){
    sf::RenderWindow m_wim {sf::VideoMode(100, 100), "World"};
    bool ImGuiInit = ImGui::SFML::Init(m_win);
    bool running = true;
    sf::Clock clock;
    while (running) {
        sf::Event event;
        while (m_win.pollEvent(event)) {
            ImGui::SFML::ProcessEvent(m_win, event);
            if(event.type == sf::Event::MouseButtonReleased){
                running = false;
            }
        }
        auto deltaTime = clock.restart();
        ImGui::SFML::Update(m_win, deltaTime);
        m_win.clear();
        ImGui::SFML::Render(m_win);
        m_win.display();

    }
    ImGui::SFML::Shutdown();
}

i got this error in kde on arch