st/oxr: Purge event queue of destroyed sessions

This commit is contained in:
Jakob Bornecrantz 2020-05-30 13:26:46 +01:00
parent 185036489c
commit 76e4092e30
4 changed files with 51 additions and 1 deletions

View file

@ -0,0 +1,3 @@
OpenXR: When a `XrSession` is destroyed purge the event queue of any events that
references to it so that no events gets delivered to the applications with
stales handles.

View file

@ -133,6 +133,44 @@ oxr_event_push_XrEventDataSessionStateChanged(struct oxr_logger *log,
return XR_SUCCESS;
}
XrResult
oxr_event_remove_session_events(struct oxr_logger *log,
struct oxr_session *sess)
{
struct oxr_instance *inst = sess->sys->inst;
XrSession session = oxr_session_to_openxr(sess);
lock(inst);
struct oxr_event *e = inst->next_event;
while (e != NULL) {
struct oxr_event *cur = e;
e = e->next;
XrEventDataSessionStateChanged *changed = oxr_event_extra(cur);
if (changed->type != XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED) {
continue;
}
if (changed->session != session) {
continue;
}
if (cur == inst->next_event) {
inst->next_event = cur->next;
}
if (cur == inst->last_event) {
inst->last_event = NULL;
}
free(cur);
}
unlock(inst);
return XR_SUCCESS;
}
XrResult
oxr_poll_event(struct oxr_logger *log,
struct oxr_instance *inst,

View file

@ -692,6 +692,13 @@ oxr_event_push_XrEventDataSessionStateChanged(struct oxr_logger *log,
XrSessionState state,
XrTime time);
/*!
* This clears all pending events refers to the given session.
*/
XrResult
oxr_event_remove_session_events(struct oxr_logger *log,
struct oxr_session *sess);
/*
*

View file

@ -840,6 +840,8 @@ oxr_session_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
{
struct oxr_session *sess = (struct oxr_session *)hb;
XrResult ret = oxr_event_remove_session_events(log, sess);
// Does a null-ptr check.
xrt_comp_destroy(&sess->compositor);
@ -848,7 +850,7 @@ oxr_session_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
free(sess);
return XR_SUCCESS;
return ret;
}
#define OXR_SESSION_ALLOCATE(LOG, SYS, OUT) \