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); + } + } }