From 0a89a58ef07d0633e4310a0a8028acfb81b371eb Mon Sep 17 00:00:00 2001 From: JeroMiya Date: Wed, 30 Nov 2016 12:40:49 -0500 Subject: [PATCH] Added nullptr checks for mRenderManager in OSVRCustomPresent, OSVRCustomPresentD3D11, and OSVRCustomPresentOpenGL. --- .../Source/OSVR/Private/OSVRCustomPresent.h | 38 ++++++++++++++++--- .../OSVR/Private/OSVRCustomPresentD3D11.h | 12 +++++- .../OSVR/Private/OSVRCustomPresentOpenGL.h | 12 ++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h index 02e0dd2..6d2c4f6 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h @@ -135,12 +135,21 @@ class FOSVRCustomPresent : public FRHICustomPresent virtual OSVR_Pose3 GetHeadPoseFromCachedRenderInfoCollection(bool renderThread, bool updateCache) { FScopeLock lock(&mOSVRMutex); + OSVR_Pose3 ret; + osvrPose3SetIdentity(&ret); + OSVR_RenderInfoCollection& renderInfoCollection = renderThread ? mCachedRenderThreadRenderInfoCollection : mCachedGameThreadRenderInfoCollection; if (updateCache) { - UpdateCachedRenderInfoCollection(renderInfoCollection); + if (!UpdateCachedRenderInfoCollection(renderInfoCollection)) + { + UE_LOG(FOSVRCustomPresentLog, Warning, + TEXT("FOSVRCustomPresent::GetHeadPoseFromCachedRenderInfoCollection could not update cached render info, returning identity pose.")); + return ret; + } } - return GetHeadPoseFromCachedRenderInfoCollectionImpl(renderInfoCollection); + ret = GetHeadPoseFromCachedRenderInfoCollectionImpl(renderInfoCollection); + return ret; } virtual void GetProjectionMatrix(OSVR_RenderInfoCount eye, float &left, float &right, float &bottom, float &top, float nearClip, float farClip) @@ -280,15 +289,34 @@ class FOSVRCustomPresent : public FRHICustomPresent virtual OSVR_Pose3 GetHeadPoseFromCachedRenderInfoCollectionImpl(OSVR_RenderInfoCollection renderInfoCollection, OSVR_RenderInfoCount index) = 0; - virtual void UpdateCachedRenderInfoCollection(OSVR_RenderInfoCollection &renderInfoCollection) + virtual bool UpdateCachedRenderInfoCollection(OSVR_RenderInfoCollection &renderInfoCollection) { OSVR_ReturnCode rc; + if (!mRenderManager) + { + UE_LOG(FOSVRCustomPresentLog, Warning, + TEXT("OSVRCustomPresent::UpdateCachedRenderInfoCollection: mRenderManager is not yet initialized.")); + return false; + } + if (renderInfoCollection) { rc = osvrRenderManagerReleaseRenderInfoCollection(renderInfoCollection); - check(rc == OSVR_RETURN_SUCCESS); + if (rc != OSVR_RETURN_SUCCESS) + { + UE_LOG(FOSVRCustomPresentLog, Warning, + TEXT("OSVRCustomPresent::UpdateCachedRenderInfoCollection: osvrRenderManagerReleaseRenderInfoCollection call failed.")); + return false; + } } rc = osvrRenderManagerGetRenderInfoCollection(mRenderManager, mRenderParams, &renderInfoCollection); - check(rc == OSVR_RETURN_SUCCESS); + if (rc != OSVR_RETURN_SUCCESS) + { + UE_LOG(FOSVRCustomPresentLog, Warning, + TEXT("OSVRCustomPresent::UpdateCachedRenderInfoCollection: osvrRenderManagerGetRenderInfoCollection call failed.")); + return false; + } + + return true; } template diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentD3D11.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentD3D11.h index e32244b..2699f07 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentD3D11.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentD3D11.h @@ -293,6 +293,8 @@ class FDirect3D11CustomPresent : public FOSVRCustomPresent// bInitialized = true; } + // mRenderManager must be non-nullptr if we're returning true. + check(mRenderManager); return true; } @@ -326,6 +328,13 @@ class FDirect3D11CustomPresent : public FOSVRCustomPresent// check(IsInitialized()); check(IsInRenderingThread()); + if (!mRenderManager) + { + UE_LOG(FOSVRCustomPresentLog, Warning, + TEXT("FDirect3D11CustomPresent::FinishRendering() - mRenderManager is null. Should be non-null at this point.")); + return; + } + if (!mCachedRenderThreadRenderInfoCollection) { UE_LOG(FOSVRCustomPresentLog, Warning, @@ -388,7 +397,8 @@ class FDirect3D11CustomPresent : public FOSVRCustomPresent// HRESULT hr; check(IsInRenderingThread()); check(IsInitialized()); - + check(mRenderManager); + if (bRenderBuffersNeedToUpdate) { if (!bDisplayOpen) diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h index 5f77137..e1b58ac 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h @@ -349,6 +349,9 @@ class FOpenGLCustomPresent : public FOSVRCustomPresent // LazyOpenDisplay needs to be called on the rendering thread to open the display bInitialized = true; } + + // mRenderManager must be non-nullptr if we're returning true. + check(mRenderManager); return true; } @@ -408,6 +411,13 @@ class FOpenGLCustomPresent : public FOSVRCustomPresent { check(IsInitialized()); + if (!mRenderManager) + { + UE_LOG(FOSVRCustomPresentLog, Warning, + TEXT("FOpenGLCustomPresent::FinishRendering() - mRenderManager is null. Should be non-null at this point.")); + return; + } + // @todo: this needs to be more robust. // Can we find this by inspection of the view somehow? // After the first call, the framebuffer ends up set to @@ -447,6 +457,8 @@ class FOpenGLCustomPresent : public FOSVRCustomPresent OSVR_ReturnCode rc; check(IsInitialized()); + check(mRenderManager); + if (bRenderBuffersNeedToUpdate) { //check(RenderTargetTexture);