Skip to content

Commit

Permalink
Add error checking when ending the frame
Browse files Browse the repository at this point in the history
  • Loading branch information
janhsimon committed Aug 26, 2024
1 parent 230e476 commit 0cf115b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Headset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ Headset::BeginFrameResult Headset::beginFrame(uint32_t& swapchainImageIndex)
return BeginFrameResult::Error;
}

if ((viewState.viewStateFlags & XR_VIEW_STATE_POSITION_VALID_BIT) == 0)
{
util::error(Error::GenericOpenXR);
return BeginFrameResult::Error;
}

if ((viewState.viewStateFlags & XR_VIEW_STATE_ORIENTATION_VALID_BIT) == 0)
{
util::error(Error::GenericOpenXR);
return BeginFrameResult::Error;
}

// Update the eye render infos, view and projection matrices
for (size_t eyeIndex = 0u; eyeIndex < eyeCount; ++eyeIndex)
{
Expand Down Expand Up @@ -566,6 +578,7 @@ void Headset::endFrame() const
XrResult result = xrReleaseSwapchainImage(swapchain, &swapchainImageReleaseInfo);
if (XR_FAILED(result))
{
util::error(Error::GenericOpenXR);
return;
}

Expand All @@ -576,10 +589,7 @@ void Headset::endFrame() const
compositionLayerProjection.views = eyeRenderInfos.data();

std::vector<XrCompositionLayerBaseHeader*> layers;

const bool positionValid = viewState.viewStateFlags & XR_VIEW_STATE_POSITION_VALID_BIT;
const bool orientationValid = viewState.viewStateFlags & XR_VIEW_STATE_ORIENTATION_VALID_BIT;
if (frameState.shouldRender && positionValid && orientationValid)
if (frameState.shouldRender)
{
layers.push_back(reinterpret_cast<XrCompositionLayerBaseHeader*>(&compositionLayerProjection));
}
Expand All @@ -592,6 +602,7 @@ void Headset::endFrame() const
result = xrEndFrame(session, &frameEndInfo);
if (XR_FAILED(result))
{
util::error(Error::GenericOpenXR);
return;
}
}
Expand Down

0 comments on commit 0cf115b

Please sign in to comment.