Backends: Metal4: ImGui_ImplMetal4_NewFrame() waits forever with framesInFlight > 1 once a secondary viewport is rendered #9624

Closed
opened 2026-11-11 17:13:31 +00:00 by lailoken · 0 comments
lailoken commented 2026-11-11 17:13:31 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version 1.93.1 WIP, Branch: docking (cf53467ab)

Back-ends:

imgui_impl_sdl3.cpp + imgui_impl_metal4.mm

Compiler, OS:

macOS 27.0.1 (Apple Silicon) + Apple Clang 21

Full config/build information:

No response

Details:

My Issue/Question:

With more than one frame in flight, the application freezes on the frame after a secondary viewport was first rendered: ImGui_ImplMetal4_NewFrame() never returns.

ImGui_ImplMetal_RenderWindow() signals events[currentFrameSlot] with a single global ++eventValue, while ImGui_ImplMetal4_NewFrame(slot) waits on events[slot] for that global value with timeoutMS:UINT64_MAX. The next frame uses another slot, whose event never reaches that value.

Reproduces in the unmodified example_sdl3_metal4 (FRAMES_IN_FLIGHT 3, viewports enabled): drag any window out of the main window, or paste the code below. The main thread is then stuck in -[MTLSharedEvent waitUntilSignaledValue:timeoutMS:] called from ImGui_ImplMetal4_NewFrame(). Not affected with FRAMES_IN_FLIGHT 1.

Fix proposed in #9621.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// examples/example_sdl3_metal4/main.mm (docking), anywhere between ImGui::NewFrame() and ImGui::Render().
// Creates a window outside the main viewport; same as dragging any window out of the main window.
const ImGuiViewport* main_viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(ImVec2(main_viewport->Pos.x + main_viewport->Size.x + 20.0f, main_viewport->Pos.y), ImGuiCond_Appearing);
ImGui::Begin("Outside the main viewport");
ImGui::Text("Hello from a secondary viewport!");
ImGui::End();
### Version/Branch of Dear ImGui: Version 1.93.1 WIP, Branch: docking (cf53467ab) ### Back-ends: imgui_impl_sdl3.cpp + imgui_impl_metal4.mm ### Compiler, OS: macOS 27.0.1 (Apple Silicon) + Apple Clang 21 ### Full config/build information: _No response_ ### Details: **My Issue/Question:** With more than one frame in flight, the application freezes on the frame after a secondary viewport was first rendered: `ImGui_ImplMetal4_NewFrame()` never returns. `ImGui_ImplMetal_RenderWindow()` signals `events[currentFrameSlot]` with a single global `++eventValue`, while `ImGui_ImplMetal4_NewFrame(slot)` waits on `events[slot]` for that global value with `timeoutMS:UINT64_MAX`. The next frame uses another slot, whose event never reaches that value. Reproduces in the unmodified example_sdl3_metal4 (`FRAMES_IN_FLIGHT 3`, viewports enabled): drag any window out of the main window, or paste the code below. The main thread is then stuck in `-[MTLSharedEvent waitUntilSignaledValue:timeoutMS:]` called from `ImGui_ImplMetal4_NewFrame()`. Not affected with `FRAMES_IN_FLIGHT 1`. Fix proposed in #9621. ### Screenshots/Video: _No response_ ### Minimal, Complete and Verifiable Example code: ```cpp // examples/example_sdl3_metal4/main.mm (docking), anywhere between ImGui::NewFrame() and ImGui::Render(). // Creates a window outside the main viewport; same as dragging any window out of the main window. const ImGuiViewport* main_viewport = ImGui::GetMainViewport(); ImGui::SetNextWindowPos(ImVec2(main_viewport->Pos.x + main_viewport->Size.x + 20.0f, main_viewport->Pos.y), ImGuiCond_Appearing); ImGui::Begin("Outside the main viewport"); ImGui::Text("Hello from a secondary viewport!"); ImGui::End(); ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#9624
No description provided.