Backends: Win32: Fixed setting of io.DisplaySize to invalid/uninitialized data when after hwnd has been closed.

GetClientRect() fails on closed hwnd which left the rectangle uninitialized and copied to DisplaySize. Ensure it is zero + similar failsafe in io.WantSetMousePos path.
This commit is contained in:
ocornut
2020-12-04 11:48:17 +01:00
parent 998d7303b1
commit f9b873662b
2 changed files with 6 additions and 4 deletions

View File

@ -32,6 +32,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2020-12-04: Misc: Fixed setting of io.DisplaySize to invalid/uninitialized data when after hwnd has been closed.
// 2020-03-03: Inputs: Calling AddInputCharacterUTF16() to support surrogate pairs leading to codepoint >= 0x10000 (for more complete CJK inputs)
// 2020-02-17: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helper functions.
// 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT.
@ -153,8 +154,8 @@ static void ImGui_ImplWin32_UpdateMousePos()
if (io.WantSetMousePos)
{
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
::ClientToScreen(g_hWnd, &pos);
::SetCursorPos(pos.x, pos.y);
if (::ClientToScreen(g_hWnd, &pos))
::SetCursorPos(pos.x, pos.y);
}
// Set mouse position
@ -221,12 +222,12 @@ void ImGui_ImplWin32_NewFrame()
IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer backend. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplOpenGL3_NewFrame().");
// Setup display size (every frame to accommodate for window resizing)
RECT rect;
RECT rect = { 0, 0, 0, 0 };
::GetClientRect(g_hWnd, &rect);
io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
// Setup time step
INT64 current_time;
INT64 current_time = 0;
::QueryPerformanceCounter((LARGE_INTEGER*)&current_time);
io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
g_Time = current_time;