st/oxr: add more checks around xrBeginSession and xrEndSession

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2162>
This commit is contained in:
Simon Zeni 2024-03-07 13:29:29 -05:00 committed by Rylie Pavlik
parent 511efda748
commit 738acfbcf7
2 changed files with 22 additions and 1 deletions

View file

@ -0,0 +1 @@
st/oxr: add more checks around xrBeginSession and xrEndSession

View file

@ -205,6 +205,14 @@ oxr_session_enumerate_formats(struct oxr_logger *log,
XrResult
oxr_session_begin(struct oxr_logger *log, struct oxr_session *sess, const XrSessionBeginInfo *beginInfo)
{
/*
* If the session is not running when the application calls xrBeginSession, but the session is not yet in the
* XR_SESSION_STATE_READY state, the runtime must return error XR_ERROR_SESSION_NOT_READY.
*/
if (sess->state != XR_SESSION_STATE_READY) {
return oxr_error(log, XR_ERROR_SESSION_NOT_READY, "Session is not ready to begin");
}
struct xrt_compositor *xc = sess->compositor;
if (xc != NULL) {
XrViewConfigurationType view_type = beginInfo->primaryViewConfigurationType;
@ -267,11 +275,23 @@ oxr_session_end(struct oxr_logger *log, struct oxr_session *sess)
return XR_SUCCESS;
}
struct xrt_compositor *xc = sess->compositor;
/*
* If the session is not running when the application calls xrEndSession, the runtime must return
* error XR_ERROR_SESSION_NOT_RUNNING
*/
if (sess->state == XR_SESSION_STATE_IDLE || sess->state == XR_SESSION_STATE_READY) {
return oxr_error(log, XR_ERROR_SESSION_NOT_RUNNING, "Session is not running");
}
/*
* If the session is still running when the application calls xrEndSession, but the session is not yet in
* the XR_SESSION_STATE_STOPPING state, the runtime must return error XR_ERROR_SESSION_NOT_STOPPING.
*/
if (sess->state != XR_SESSION_STATE_STOPPING) {
return oxr_error(log, XR_ERROR_SESSION_NOT_STOPPING, "Session is not stopping");
}
struct xrt_compositor *xc = sess->compositor;
if (xc != NULL) {
if (sess->frame_id.waited > 0) {
xrt_comp_discard_frame(xc, sess->frame_id.waited);