fix vr shutdown
This commit is contained in:
18
src/main.cpp
18
src/main.cpp
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user