Skip to content

Commit d0021e1

Browse files
committed
Backends: Metal: Fixed resource leak when using multiple contexts. (ocornut#7419)
1 parent 2f1194a commit d0021e1

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

backends/imgui_impl_metal.mm

+4-7
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,14 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* drawData, id<MTLCommandBuffer> c
306306
indexBufferOffset += (size_t)draw_list->IdxBuffer.Size * sizeof(ImDrawIdx);
307307
}
308308

309+
__block MetalContext* sharedMetalContext = bd->SharedMetalContext;
309310
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer>)
310311
{
311312
dispatch_async(dispatch_get_main_queue(), ^{
312-
ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
313-
if (bd != nullptr)
313+
@synchronized(bd->SharedMetalContext.bufferCache)
314314
{
315-
@synchronized(bd->SharedMetalContext.bufferCache)
316-
{
317-
[bd->SharedMetalContext.bufferCache addObject:vertexBuffer];
318-
[bd->SharedMetalContext.bufferCache addObject:indexBuffer];
319-
}
315+
[sharedMetalContext.bufferCache addObject:vertexBuffer];
316+
[sharedMetalContext.bufferCache addObject:indexBuffer];
320317
}
321318
});
322319
}];

docs/CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Other changes:
6464
- Misc: Fixed misc/cpp/imgui_stdlib.h/.cpp not supporting IMGUI_DISABLE. (#8294) [@juur]
6565
- Backends: Allegro5: Avoid calling al_set_mouse_cursor() repeatedly since it appears
6666
to leak on on X11 (#8256). [@Helodity]
67+
- Backends: Metal: Fixed resource leak when using multiple contexts. (#7419) [@anszom]
6768
- Backends: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for
6869
platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222) [@Zer0xFF]
6970

0 commit comments

Comments
 (0)