st/oxr: Fix hand joint location flags not cleared when inactive
Consolidate error/inactive paths in oxr_session_hand_joints() to ensure joint location and velocity flags are always properly cleared when hand-tracking is not active. Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2653>
1469 unmodified linesExpand all1470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149517 unmodified lines15131514151515161507151715181519152015211522152315141515152415251526152715191520152115221523152415281529153015314 unmodified lines153615371538153915371538154015411542154015431544154215431544154515451546154715482 unmodified lines15511552155315541556155715581559156015611562156315641565156615671555155615571558155933 unmodified lines15931594159515961609159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620236 unmodified linesExpand all1469 unmodified linesExpand all struct oxr_hand_tracker *hand_tracker, const XrHandJointsLocateInfoEXT *locateInfo, XrHandJointLocationsEXT *locations){ XrResult ret = XR_SUCCESS;
struct oxr_space *baseSpc = XRT_CAST_OXR_HANDLE_TO_PTR(struct oxr_space *, locateInfo->baseSpace);
struct oxr_session *sess = hand_tracker->sess; struct oxr_instance *inst = sess->sys->inst;
XrHandJointVelocitiesEXT *vel = OXR_GET_OUTPUT_FROM_CHAIN(locations, XR_TYPE_HAND_JOINT_VELOCITIES_EXT, XrHandJointVelocitiesEXT);
#ifdef OXR_HAVE_EXT_hand_tracking_data_source XrHandTrackingDataSourceStateEXT *data_source_state = NULL; if (hand_tracker->sess->sys->inst->extensions.EXT_hand_tracking_data_source) { data_source_state = OXR_GET_OUTPUT_FROM_CHAIN(locations, XR_TYPE_HAND_TRACKING_DATA_SOURCE_STATE_EXT, XrHandTrackingDataSourceStateEXT); }#endif
const XrTime at_time = locateInfo->time;
//! Convert at_time to monotonic and give to device. const int64_t at_timestamp_ns = time_state_ts_to_monotonic_ns(inst->timekeeping, at_time);17 unmodified lines int64_t ignored; value = (struct xrt_hand_joint_set){0}; xrt_result_t xret = xrt_device_get_hand_tracking(data_source->xdev, data_source->input_name, at_timestamp_ns, &value, &ignored); OXR_CHECK_XRET(log, sess, xret, xrt_device_get_hand_tracking); OXR_CHECK_XRET_GOTO(log, sess, xret, xrt_device_get_hand_tracking, ret, hand_tracking_inactive); if (value.is_active) { break; } }
if (data_source == NULL || data_source->xdev == NULL) { locations->isActive = false; return XR_SUCCESS; goto hand_tracking_inactive; }
#ifdef OXR_HAVE_EXT_hand_tracking_data_source XrHandTrackingDataSourceStateEXT *data_source_state = NULL; if (hand_tracker->sess->sys->inst->extensions.EXT_hand_tracking_data_source) { data_source_state = OXR_GET_OUTPUT_FROM_CHAIN(locations, XR_TYPE_HAND_TRACKING_DATA_SOURCE_STATE_EXT, XrHandTrackingDataSourceStateEXT); }
if (data_source_state != NULL) { data_source_state->isActive = XR_TRUE; data_source_state->dataSource = xrt_hand_tracking_data_source_to_xr(data_source->input_name); }4 unmodified lines
// Get the xdev's pose in the base space. struct xrt_space_relation T_base_xdev = XRT_SPACE_RELATION_ZERO;
XrResult ret = oxr_space_locate_device(log, data_source->xdev, baseSpc, at_time, &T_base_xdev); if (ret != XR_SUCCESS) { ret = oxr_space_locate_device(log, data_source->xdev, baseSpc, at_time, &T_base_xdev); if (ret != XR_SUCCESS || T_base_xdev.relation_flags == 0) { // Error printed logged oxr_space_locate_device return ret; goto hand_tracking_inactive; } if (T_base_xdev.relation_flags == 0) { locations->isActive = false; return XR_SUCCESS; }
// Get the hands pose in the base space. struct xrt_space_relation T_base_hand; struct xrt_relation_chain xrc = {0};2 unmodified lines m_relation_chain_resolve(&xrc, &T_base_hand);
// Can we not relate to this space or did we not get values? if (T_base_hand.relation_flags == 0 || !value.is_active) { locations->isActive = false;
// Loop over all joints and zero flags. for (uint32_t i = 0; i < locations->jointCount; i++) { locations->jointLocations[i].locationFlags = XRT_SPACE_RELATION_BITMASK_NONE; if (vel) { XrHandJointVelocityEXT *v = &vel->jointVelocities[i]; v->velocityFlags = XRT_SPACE_RELATION_BITMASK_NONE; } }
return XR_SUCCESS; goto hand_tracking_inactive; }
// We know we are active. locations->isActive = true;33 unmodified lines v->angularVelocity.z = result.angular_velocity.z; } }
return XR_SUCCESS; return ret;
hand_tracking_inactive: locations->isActive = XR_FALSE;
#ifdef OXR_HAVE_EXT_hand_tracking_data_source if (data_source_state != NULL) { data_source_state->isActive = XR_FALSE; }#endif
// Loop over all joints and zero flags. for (uint32_t i = 0; i < locations->jointCount; i++) { locations->jointLocations[i].locationFlags = XRT_SPACE_RELATION_BITMASK_NONE; if (vel) { vel->jointVelocities[i].velocityFlags = XRT_SPACE_RELATION_BITMASK_NONE; } }
return ret;}
/* * Gets the body pose in the base space.236 unmodified linesExpand all