WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit ee71810

Browse files
committed
don't render all the time sample hang fix (wm_quit in the inner untreated)
1 parent 875a03f commit ee71810

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

examples/example_win32_directx12/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ int main(int, char**)
132132

133133
// Start the Dear ImGui frame
134134
ImGui_ImplDX12_NewFrame();
135-
ImGui_ImplWin32_NewFrame();
135+
if (!ImGui_ImplWin32_NewFrame())
136+
break;
137+
136138
ImGui::NewFrame();
137139

138140
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).

examples/imgui_impl_win32.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static void ImGui_ImplWin32_UpdateGamepads()
217217
#endif // #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD
218218
}
219219

220-
void ImGui_ImplWin32_NewFrame()
220+
bool ImGui_ImplWin32_NewFrame()
221221
{
222222
ImGuiIO& io = ImGui::GetIO();
223223
IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer back-end. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplOpenGL3_NewFrame().");
@@ -238,13 +238,17 @@ void ImGui_ImplWin32_NewFrame()
238238

239239
MSG msg;
240240
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
241-
{
242-
::TranslateMessage(&msg);
243-
::DispatchMessage(&msg);
244-
continue;
241+
{
242+
if (msg.message != WM_QUIT)
243+
{
244+
::TranslateMessage(&msg);
245+
::DispatchMessage(&msg);
246+
continue;
247+
}
248+
return false;
245249
}
246250

247-
::QueryPerformanceCounter((LARGE_INTEGER*)&current_time);
251+
::QueryPerformanceCounter((LARGE_INTEGER*)&current_time);
248252
continue;
249253
}
250254
break;
@@ -280,6 +284,8 @@ void ImGui_ImplWin32_NewFrame()
280284

281285
// Update game controllers (if enabled and available)
282286
ImGui_ImplWin32_UpdateGamepads();
287+
288+
return true;
283289
}
284290

285291
// Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions.
@@ -383,6 +389,8 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
383389
if ((UINT)wParam == DBT_DEVNODES_CHANGED)
384390
g_WantUpdateHasGamepad = true;
385391
return 0;
392+
case WM_CLOSE:
393+
io.NextRefresh = 0.0f;
386394
}
387395
return 0;
388396
}

examples/imgui_impl_win32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd);
1414
IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown();
15-
IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame();
15+
IMGUI_IMPL_API bool ImGui_ImplWin32_NewFrame();
1616

1717
// Configuration
1818
// - Disable gamepad support or linking with xinput.lib

0 commit comments

Comments
 (0)