From 269b92d93c5429dcd6becb132ee3ffcb3469637e Mon Sep 17 00:00:00 2001 From: Shane Davis Date: Sun, 22 May 2022 17:19:25 -0700 Subject: [PATCH] fix crash when no HMD detected --- L4D2VR/hooks.cpp | 9 ++++++--- L4D2VR/vr.cpp | 2 ++ L4D2VR/vr.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/L4D2VR/hooks.cpp b/L4D2VR/hooks.cpp index 3a1e957..5b96b11 100644 --- a/L4D2VR/hooks.cpp +++ b/L4D2VR/hooks.cpp @@ -210,9 +210,12 @@ HRESULT __stdcall Hooks::dPresent(IDirect3DDevice9 *pDevice, const RECT *pSource iD9on12->ReturnUnderlyingResource(mVR->d9RightEyeTexture, 0, nullptr, nullptr); } - mVR->UpdatePosesAndActions(); - mVR->UpdateTracking(mVR->setupOrigin); - + if (mVR->isInitialized) + { + mVR->UpdatePosesAndActions(); + mVR->UpdateTracking(mVR->setupOrigin); + } + return hkPresent.fOriginal(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); } diff --git a/L4D2VR/vr.cpp b/L4D2VR/vr.cpp index ba8bfa4..929925a 100644 --- a/L4D2VR/vr.cpp +++ b/L4D2VR/vr.cpp @@ -72,6 +72,8 @@ VR::VR(Game *game) { std::thread configParser(&VR::WaitForConfigUpdate, this); configParser.detach(); + + isInitialized = true; } diff --git a/L4D2VR/vr.h b/L4D2VR/vr.h index 72924fa..145fcc4 100644 --- a/L4D2VR/vr.h +++ b/L4D2VR/vr.h @@ -101,6 +101,7 @@ class VR IDirect3DTexture9 *d9RightEyeTexture; bool isVREnabled; + bool isInitialized; bool mPressedLeftStick = false; bool mChangedItem = false;