use mutex to avoid window destroy deadlock, fix vertical slider to increase value upward

This commit is contained in:
2019-03-04 19:32:43 +01:00
parent 6e73a9eee5
commit 801db87e06
9 changed files with 103 additions and 71 deletions

View File

@@ -33,6 +33,7 @@ std::thread hmd_renderer;
std::thread renderer;
int running = -1;
std::mutex render_mutex;
std::mutex wnd_mutex;
std::condition_variable render_cv;
int gl_count = 0;
@@ -646,8 +647,13 @@ int main(int argc, char** argv)
{
static wchar_t title_fps[512];
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
if (running)
// lock if
if (wnd_mutex.try_lock())
{
SetWindowText(hWnd, title_fps);
wnd_mutex.unlock();
}
one_sec = 0;
frames = 0;
}
@@ -806,10 +812,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
running = 0;
render_cv.notify_all();
if (renderer.joinable())
renderer.join();
if (hmd_renderer.joinable())
hmd_renderer.join();
{
// avoid deadlock
// nobody should call windows API on this window at this time
std::lock_guard<std::mutex> lock(wnd_mutex);
if (renderer.joinable())
renderer.join();
if (hmd_renderer.joinable())
hmd_renderer.join();
}
App::I.terminate();
}
break;