Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added nullptr checks for mRenderManager in OSVRCustomPresent, OSVRCustomPresentD3D11, and OSVRCustomPresentOpenGL. #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the other messages will appear each time a frame tries to render, right? That's a lot of messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably limit it, but if they're getting it every frame something more serious is wrong instead of just a transient error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

TEXT("OSVRCustomPresent::UpdateCachedRenderInfoCollection: osvrRenderManagerGetRenderInfoCollection call failed."));
return false;
}

return true;
}

template<class TGraphicsDevice>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class FDirect3D11CustomPresent : public FOSVRCustomPresent//<ID3D11Device>

bInitialized = true;
}
// mRenderManager must be non-nullptr if we're returning true.
check(mRenderManager);
return true;
}

Expand Down Expand Up @@ -326,6 +328,13 @@ class FDirect3D11CustomPresent : public FOSVRCustomPresent//<ID3D11Device>
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,
Expand Down Expand Up @@ -388,7 +397,8 @@ class FDirect3D11CustomPresent : public FOSVRCustomPresent//<ID3D11Device>
HRESULT hr;
check(IsInRenderingThread());
check(IsInitialized());

check(mRenderManager);

if (bRenderBuffersNeedToUpdate)
{
if (!bDisplayOpen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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."));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this message say that rendering won't work and then remove the later messages but keep the checks?

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
Expand Down Expand Up @@ -447,6 +457,8 @@ class FOpenGLCustomPresent : public FOSVRCustomPresent
OSVR_ReturnCode rc;

check(IsInitialized());
check(mRenderManager);

if (bRenderBuffersNeedToUpdate)
{
//check(RenderTargetTexture);
Expand Down