The open source OpenXR runtime

st/oxr: add more checks around xrBeginSession and xrEndSession

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2162>

authored by Simon Zeni and committed by Rylie Pavlik 738acfbc 511efda7

Changed files
+22 -1
doc
changes
state_trackers
src
xrt
state_trackers
+1
doc/changes/state_trackers/mr.2162.md
··· 1 + st/oxr: add more checks around xrBeginSession and xrEndSession
+21 -1
src/xrt/state_trackers/oxr/oxr_session.c
··· 205 205 XrResult 206 206 oxr_session_begin(struct oxr_logger *log, struct oxr_session *sess, const XrSessionBeginInfo *beginInfo) 207 207 { 208 + /* 209 + * If the session is not running when the application calls xrBeginSession, but the session is not yet in the 210 + * XR_SESSION_STATE_READY state, the runtime must return error XR_ERROR_SESSION_NOT_READY. 211 + */ 212 + if (sess->state != XR_SESSION_STATE_READY) { 213 + return oxr_error(log, XR_ERROR_SESSION_NOT_READY, "Session is not ready to begin"); 214 + } 215 + 208 216 struct xrt_compositor *xc = sess->compositor; 209 217 if (xc != NULL) { 210 218 XrViewConfigurationType view_type = beginInfo->primaryViewConfigurationType; ··· 267 275 return XR_SUCCESS; 268 276 } 269 277 270 - struct xrt_compositor *xc = sess->compositor; 278 + /* 279 + * If the session is not running when the application calls xrEndSession, the runtime must return 280 + * error XR_ERROR_SESSION_NOT_RUNNING 281 + */ 282 + if (sess->state == XR_SESSION_STATE_IDLE || sess->state == XR_SESSION_STATE_READY) { 283 + return oxr_error(log, XR_ERROR_SESSION_NOT_RUNNING, "Session is not running"); 284 + } 285 + 286 + /* 287 + * If the session is still running when the application calls xrEndSession, but the session is not yet in 288 + * the XR_SESSION_STATE_STOPPING state, the runtime must return error XR_ERROR_SESSION_NOT_STOPPING. 289 + */ 271 290 if (sess->state != XR_SESSION_STATE_STOPPING) { 272 291 return oxr_error(log, XR_ERROR_SESSION_NOT_STOPPING, "Session is not stopping"); 273 292 } 274 293 294 + struct xrt_compositor *xc = sess->compositor; 275 295 if (xc != NULL) { 276 296 if (sess->frame_id.waited > 0) { 277 297 xrt_comp_discard_frame(xc, sess->frame_id.waited);