From 28c317c55769110b4f83003aa9e868f66157b3fe Mon Sep 17 00:00:00 2001
From: briaguya <70942617+briaguya-ai@users.noreply.github.com>
Date: Sat, 17 May 2025 04:41:55 -0400
Subject: [PATCH 1/3] Revert "Backends: Metal: Fixed memory leaks. (#8276,
 #8166)"

This reverts commit e6a7c7689f57038b2519fe43e55e3d57103ad0f7.
---
 backends/imgui_impl_metal.mm | 8 --------
 docs/CHANGELOG.txt           | 1 -
 2 files changed, 9 deletions(-)

diff --git a/backends/imgui_impl_metal.mm b/backends/imgui_impl_metal.mm
index 9ab4a342adfd..388c4f3984e1 100644
--- a/backends/imgui_impl_metal.mm
+++ b/backends/imgui_impl_metal.mm
@@ -18,7 +18,6 @@
 // (minor and older changes stripped away, please see git history for details)
 //  2025-XX-XX: Metal: Added support for multiple windows via the ImGuiPlatformIO interface.
 //  2025-02-03: Metal: Crash fix. (#8367)
-//  2025-01-08: Metal: Fixed memory leaks when using metal-cpp (#8276, #8166) or when using multiple contexts (#7419).
 //  2022-08-23: Metal: Update deprecated property 'sampleCount'->'rasterSampleCount'.
 //  2022-07-05: Metal: Add dispatch synchronization.
 //  2022-06-30: Metal: Use __bridge for ARC based systems.
@@ -171,11 +170,7 @@ void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor)
 {
     ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
     IM_ASSERT(bd != nil && "Context or backend not initialized! Did you call ImGui_ImplMetal_Init()?");
-#ifdef IMGUI_IMPL_METAL_CPP
-    bd->SharedMetalContext.framebufferDescriptor = [[[FramebufferDescriptor alloc] initWithRenderPassDescriptor:renderPassDescriptor]autorelease];
-#else
     bd->SharedMetalContext.framebufferDescriptor = [[FramebufferDescriptor alloc] initWithRenderPassDescriptor:renderPassDescriptor];
-#endif
     if (bd->SharedMetalContext.depthStencilState == nil)
         ImGui_ImplMetal_CreateDeviceObjects(bd->SharedMetalContext.device);
 }
@@ -383,9 +378,6 @@ bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device)
     depthStencilDescriptor.depthCompareFunction = MTLCompareFunctionAlways;
     bd->SharedMetalContext.depthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDescriptor];
     ImGui_ImplMetal_CreateDeviceObjectsForPlatformWindows();
-#ifdef IMGUI_IMPL_METAL_CPP
-    [depthStencilDescriptor release];
-#endif
     ImGui_ImplMetal_CreateFontsTexture(device);
     return true;
 }
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 6c4f19cfef02..e4a4cbf98ef6 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -355,7 +355,6 @@ Other changes:
   though it is currently not doing anything particular. (#8163, #7998, #7988)
 - Backends: Allegro5: Avoid calling al_set_mouse_cursor() repeatedly since it appears
   to leak on on X11 (#8256). [@Helodity]
-- Backends: Metal: Fixed leaks when using metal-cpp. (#8276, #8166) [@selimsandal]
 - Backends: Metal: Fixed resource leak when using multiple contexts. (#7419) [@anszom]
 - Backends: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for
   platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222) [@Zer0xFF]

From 56f5907cf5224e1a2f64289029cc2b46e51d3b6c Mon Sep 17 00:00:00 2001
From: briaguya <70942617+briaguya-ai@users.noreply.github.com>
Date: Sat, 17 May 2025 04:42:41 -0400
Subject: [PATCH 2/3] gamepad fix

---
 backends/imgui_impl_sdl2.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp
index f3a31c5c3c5e..2e6a1ad9d1f1 100644
--- a/backends/imgui_impl_sdl2.cpp
+++ b/backends/imgui_impl_sdl2.cpp
@@ -845,9 +845,6 @@ static void ImGui_ImplSDL2_UpdateGamepads()
         bd->WantUpdateGamepadsList = false;
     }
 
-    // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
-    if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
-        return;
     io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
     if (bd->Gamepads.Size == 0)
         return;

From 90c4297624a0fe993f1ac0e538bccdc80a0fc5f2 Mon Sep 17 00:00:00 2001
From: briaguya <70942617+briaguya-ai@users.noreply.github.com>
Date: Sat, 17 May 2025 04:42:56 -0400
Subject: [PATCH 3/3] config

---
 imconfig.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/imconfig.h b/imconfig.h
index a1e29e849bc8..ee64116ff0cf 100644
--- a/imconfig.h
+++ b/imconfig.h
@@ -110,7 +110,7 @@
         operator MyVec4() const { return MyVec4(x,y,z,w); }
 */
 //---- ...Or use Dear ImGui's own very basic math operators.
-//#define IMGUI_DEFINE_MATH_OPERATORS
+#define IMGUI_DEFINE_MATH_OPERATORS
 
 //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
 // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
@@ -139,3 +139,6 @@ namespace ImGui
     void MyFunction(const char* name, MyMatrix44* mtx);
 }
 */
+
+// handle https://github.com/ocornut/imgui/issues/1641 the old way
+#define ImTextureID void*
