Ver Fonte

Backends: Allegro5: Avoid calling al_set_mouse_cursor() repeatedly since it appears to leak on on X11 (#8256).

Helodity há 7 meses atrás
pai
commit
2d2c7d3f95
2 ficheiros alterados com 14 adições e 2 exclusões
  1. 12 2
      backends/imgui_impl_allegro5.cpp
  2. 2 0
      docs/CHANGELOG.txt

+ 12 - 2
backends/imgui_impl_allegro5.cpp

@@ -20,6 +20,7 @@
 
 // CHANGELOG
 // (minor and older changes stripped away, please see git history for details)
+//  2025-01-06: Avoid calling al_set_mouse_cursor() repeatedly since it appears to leak on on X11 (#8256).
 //  2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
 //               - io.GetClipboardTextFn    -> platform_io.Platform_GetClipboardTextFn
 //               - io.SetClipboardTextFn    -> platform_io.Platform_SetClipboardTextFn
@@ -95,6 +96,7 @@ struct ImGui_ImplAllegro5_Data
     ALLEGRO_MOUSE_CURSOR*       MouseCursorInvisible;
     ALLEGRO_VERTEX_DECL*        VertexDecl;
     char*                       ClipboardTextData;
+    ImGuiMouseCursor            LastCursor;
 
     ImVector<ImDrawVertAllegro> BufVertices;
     ImVector<int>               BufIndices;
@@ -438,6 +440,7 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
     io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;       // We can honor GetMouseCursor() values (optional)
 
     bd->Display = display;
+    bd->LastCursor = ALLEGRO_SYSTEM_MOUSE_CURSOR_NONE;
 
     // Create custom vertex declaration.
     // Unfortunately Allegro doesn't support 32-bit packed colors so we have to convert them to 4 floats.
@@ -568,9 +571,16 @@ static void ImGui_ImplAllegro5_UpdateMouseCursor()
 
     ImGui_ImplAllegro5_Data* bd = ImGui_ImplAllegro5_GetBackendData();
     ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
-    if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
+
+    // Hide OS mouse cursor if imgui is drawing it
+    if (io.MouseDrawCursor)
+        imgui_cursor = ImGuiMouseCursor_None;
+
+    if (bd->LastCursor == imgui_cursor)
+        return;
+    bd->LastCursor = imgui_cursor;
+    if (imgui_cursor == ImGuiMouseCursor_None)
     {
-        // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
         al_set_mouse_cursor(bd->Display, bd->MouseCursorInvisible);
     }
     else

+ 2 - 0
docs/CHANGELOG.txt

@@ -60,6 +60,8 @@ Other changes:
   windows with the ImGuiWindowFlags_NoNavInputs flag. (#8231)
 - Debug Tools: Debug Log: hovering 0xXXXXXXXX values in log is allowed even
   if a popup is blocking mouse access to the debug log window. (#5855)
+- Backends: Allegro5: Avoid calling al_set_mouse_cursor() repeatedly since it appears
+  to leak on on X11 (#8256). [@Helodity]
 - Backends: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for
   platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222) [@Zer0xFF]