From e9c7771c1204f5db9fe67c164d0ac416873705f3 Mon Sep 17 00:00:00 2001 From: baffler <1980600+baffler@users.noreply.github.com> Date: Sun, 5 Apr 2020 18:55:11 -0400 Subject: [PATCH] Updated OpenVR SDK - OpenVR SDK Updated to v1.10.30 - Fixed a crash when exiting OBS --- .../win-openvr/data/win-openvr-presets.ini | 2 +- plugins/win-openvr/win-openvr.cpp | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/plugins/win-openvr/data/win-openvr-presets.ini b/plugins/win-openvr/data/win-openvr-presets.ini index 6b1e2fc..5a82ff2 100644 --- a/plugins/win-openvr/data/win-openvr-presets.ini +++ b/plugins/win-openvr/data/win-openvr-presets.ini @@ -1,4 +1,4 @@ 0.0,1.0,0.0,1.0,No cropping 0.239,0.753,0.0,1.0,Full 16:9 0.274,0.725,0.015,0.907,HTC Vive 16:9 -0.139,0.871,0.124,0.907,HTC Vive 1:1 \ No newline at end of file +0.31,0.71,0.11,0.9015,Valve Index 16:9 \ No newline at end of file diff --git a/plugins/win-openvr/win-openvr.cpp b/plugins/win-openvr/win-openvr.cpp index 6657f28..e0872c8 100644 --- a/plugins/win-openvr/win-openvr.cpp +++ b/plugins/win-openvr/win-openvr.cpp @@ -70,6 +70,8 @@ struct win_openvr { bool active; }; +bool IsVRSystemInitialized = false; + static void win_openvr_init(void *data, bool forced = false) { struct win_openvr *context = (win_openvr*)data; @@ -78,7 +80,8 @@ static void win_openvr_init(void *data, bool forced = false) return; // Dont attempt to init OVR too often due to memory leak in VR_Init - if (GetTickCount() - 5000 < context->lastCheckTick && !forced) + // TODO: OpenVR v1.10.30 should no longer have the memory leak + if (GetTickCount() - 1000 < context->lastCheckTick && !forced) { return; } @@ -93,6 +96,7 @@ static void win_openvr_init(void *data, bool forced = false) context->lastCheckTick = GetTickCount(); return; } + IsVRSystemInitialized = true; HRESULT hr; D3D_FEATURE_LEVEL featureLevel; @@ -194,7 +198,12 @@ static void win_openvr_deinit(void *data) //vr::VRCompositor()->ReleaseMirrorTextureD3D11(context->mirrorSrv); //context->mirrorSrv->Release(); - vr::VR_Shutdown(); // Releases mirrorSrv + if (IsVRSystemInitialized) + { + IsVRSystemInitialized = false; + vr::VR_Shutdown(); // Releases mirrorSrv + } + if (context->ctx11) context->ctx11->Release(); if (context->dev11) @@ -342,20 +351,23 @@ static void win_openvr_tick(void *data, float seconds) { vr::VREvent_t e; - // added NULL check here cause it was causing crashes when switching scenes that had another OpenVR capture - if (vr::VRSystem() != NULL) + if ((vr::VRSystem() != NULL) && (IsVRSystemInitialized)) { if (vr::VRSystem()->PollNextEvent(&e, sizeof(vr::VREvent_t))) { if (e.eventType == vr::VREvent_Quit) { - vr::VRSystem()->AcknowledgeQuit_UserPrompt(); // Without this SteamVR will kill OBS process when it exits - // TODO: OBS process will still be killed in some cases by SteamVR win_openvr_deinit(data); } } } + else if (context->active) + { + context->initialized = false; + win_openvr_init(data); + } + } }