Skip to content

Commit

Permalink
Updated OpenVR SDK
Browse files Browse the repository at this point in the history
- OpenVR SDK Updated to v1.10.30
- Fixed a crash when exiting OBS
  • Loading branch information
baffler committed Apr 5, 2020
1 parent 692f6e0 commit e9c7771
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugins/win-openvr/data/win-openvr-presets.ini
Original file line number Diff line number Diff line change
@@ -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
0.31,0.71,0.11,0.9015,Valve Index 16:9
24 changes: 18 additions & 6 deletions plugins/win-openvr/win-openvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

}
}

Expand Down

0 comments on commit e9c7771

Please sign in to comment.