fix vr shutdown

This commit is contained in:
2019-05-02 20:08:38 +02:00
parent 4bd8bbee3b
commit ea2cf73bdb

View File

@@ -35,6 +35,7 @@ std::map<kKey, int> vkey_map;
std::thread hmd_renderer; std::thread hmd_renderer;
std::thread renderer; std::thread renderer;
int running = -1; int running = -1;
int vr_running = 0;
std::mutex render_mutex; std::mutex render_mutex;
std::condition_variable render_cv; std::condition_variable render_cv;
@@ -475,10 +476,11 @@ bool win32_vr_start()
BT_SetTerminate(); BT_SetTerminate();
LOG("start hmd render thread"); LOG("start hmd render thread");
App::I.has_vr = true; App::I.has_vr = true;
vr_running = true;
const float target_tick_rate = 90; const float target_tick_rate = 90;
unsigned long t0 = GetTickCount(); unsigned long t0 = GetTickCount();
while (running == 1 && vive->Valid()) while (vr_running && running == 1 && vive->Valid())
{ {
std::unique_lock<std::mutex> lock(hmd_render_mutex); std::unique_lock<std::mutex> lock(hmd_render_mutex);
unsigned long t1 = GetTickCount(); unsigned long t1 = GetTickCount();
@@ -487,7 +489,7 @@ bool win32_vr_start()
vive->Update(); vive->Update();
App::I.vr_active = vive->m_active; App::I.vr_active = vive->m_active;
if (vive->m_active) if (vr_running && vive->m_active)
{ {
async_lock(); async_lock();
vive->Draw(); vive->Draw();
@@ -500,9 +502,12 @@ bool win32_vr_start()
} }
App::I.vr_active = false; App::I.vr_active = false;
App::I.has_vr = false; App::I.has_vr = false;
async_lock(); vr_running = false;
vive->Terminate(); if (async_lock_try())
async_unlock(); {
vive->Terminate();
async_unlock();
}
LOG("hmd renderer terminated"); LOG("hmd renderer terminated");
}); });
return true; return true;
@@ -512,6 +517,9 @@ void win32_vr_stop()
{ {
if (vive) if (vive)
{ {
vr_running = false;
if (hmd_renderer.joinable())
hmd_renderer.join();
vive->Terminate(); vive->Terminate();
delete vive; delete vive;
vive = nullptr; vive = nullptr;