From 738acfbcf784358ba3016d69209ed1016913a590 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Thu, 7 Mar 2024 13:29:29 -0500 Subject: [PATCH] st/oxr: add more checks around xrBeginSession and xrEndSession Part-of: --- doc/changes/state_trackers/mr.2162.md | 1 + src/xrt/state_trackers/oxr/oxr_session.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 doc/changes/state_trackers/mr.2162.md diff --git a/doc/changes/state_trackers/mr.2162.md b/doc/changes/state_trackers/mr.2162.md new file mode 100644 index 000000000..7d6e2cf62 --- /dev/null +++ b/doc/changes/state_trackers/mr.2162.md @@ -0,0 +1 @@ +st/oxr: add more checks around xrBeginSession and xrEndSession diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index 8b45de2ae..b7747a983 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -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);