From 7d3a95f42b4e6951b576435259c3b7ae88bb60a1 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sun, 28 Jul 2019 09:40:52 +0200 Subject: [PATCH] wake up windows main loop when updating fps, use PostMessage instead of the blocking SendMessage --- src/main.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index eecab7d..de9bef7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,6 +23,7 @@ #include #define WM_USER_CLOSE (WM_USER + 1) +#define WM_USER_WAKEUP (WM_USER + 2) LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp); HINSTANCE hInst; @@ -108,7 +109,7 @@ void destroy_window() { std::lock_guard lock(main_task_mutex); main_tasklist.emplace_back([=] { - SendMessage(hWnd, WM_USER_CLOSE, 0, 0); + PostMessage(hWnd, WM_USER_CLOSE, 0, 0); }); } @@ -196,10 +197,13 @@ void win32_update_fps(int frames) else swprintf_s(title_fps, L"%s - %d fps", window_title, frames); - std::lock_guard lock(main_task_mutex); - main_tasklist.emplace_back([] { - SetWindowText(hWnd, title_fps); - }); + { + std::lock_guard lock(main_task_mutex); + main_tasklist.emplace_back([] { + SetWindowText(hWnd, title_fps); + }); + } + PostMessage(hWnd, WM_USER_WAKEUP, 0, 0); } void win32_show_cursor(bool visible)