VR: Fix OpenXR state freeze on Oculus after taking off HMD

With the Oculus runtime, the VR session would freeze when taking off the HMD
and putting it back on. This was caused by the deletion of graphics resources
too early in the OpenXR state machine, at least for Oculus.
The resources will now only be freed once the session is actually destroyed.

Also fixes an issue where it wasn't possible to stop the session via the UI
when the HMD was taken off.

Reviewed By: Julian Eisel

Differential Revision: https://developer.blender.org/D7635
This commit is contained in:
Nicolas Fauvet 2020-05-07 14:00:49 +02:00 committed by Julian Eisel
parent 850a539c90
commit 6e0540671c
3 changed files with 20 additions and 13 deletions

View File

@ -465,7 +465,14 @@ void GHOST_XrContext::startSession(const GHOST_XrSessionBeginInfo *begin_info)
void GHOST_XrContext::endSession()
{
m_session->requestEnd();
if (m_session) {
if (m_session->isRunning()) {
m_session->requestEnd();
}
else {
m_session = nullptr;
}
}
}
bool GHOST_XrContext::isSessionRunning() const

View File

@ -203,13 +203,17 @@ void GHOST_XrSession::requestEnd()
xrRequestExitSession(m_oxr->session);
}
void GHOST_XrSession::end()
void GHOST_XrSession::beginSession()
{
XrSessionBeginInfo begin_info = {XR_TYPE_SESSION_BEGIN_INFO};
begin_info.primaryViewConfigurationType = m_oxr->view_type;
CHECK_XR(xrBeginSession(m_oxr->session, &begin_info), "Failed to cleanly begin the VR session.");
}
void GHOST_XrSession::endSession()
{
assert(m_oxr->session != XR_NULL_HANDLE);
CHECK_XR(xrEndSession(m_oxr->session), "Failed to cleanly end the VR session.");
unbindGraphicsContext();
m_draw_info = nullptr;
}
GHOST_XrSession::LifeExpectancy GHOST_XrSession::handleStateChangeEvent(
@ -222,16 +226,11 @@ GHOST_XrSession::LifeExpectancy GHOST_XrSession::handleStateChangeEvent(
switch (lifecycle->state) {
case XR_SESSION_STATE_READY: {
XrSessionBeginInfo begin_info = {XR_TYPE_SESSION_BEGIN_INFO};
begin_info.primaryViewConfigurationType = m_oxr->view_type;
CHECK_XR(xrBeginSession(m_oxr->session, &begin_info),
"Failed to cleanly begin the VR session.");
beginSession();
break;
}
case XR_SESSION_STATE_STOPPING:
/* Runtime will change state to STATE_EXITING, don't destruct session yet. */
end();
endSession();
break;
case XR_SESSION_STATE_EXITING:
case XR_SESSION_STATE_LOSS_PENDING:

View File

@ -68,7 +68,8 @@ class GHOST_XrSession {
std::unique_ptr<GHOST_XrDrawInfo> m_draw_info;
void initSystem();
void end();
void beginSession();
void endSession();
void bindGraphicsContext();