Repository: godotengine/godot
File: modules/openxr/openxr_interface.cpp (C++)

Code before:
			mode = XR_PLAY_AREA_UNKNOWN;
			break;
	}

	print_verbose("OpenXR Interface: Play area changed, emitting signal.");
	emit_signal(SNAME("play_area_changed"), mode);
}

void OpenXRInterface::on_refresh_rate_changes(float p_new_rate) {
	emit_signal(SNAME("refresh_rate_changed"), p_new_rate);
}

OpenXRInterface::SessionState OpenXRInterface::get_session_state() {
	if (openxr_api) {
		return (SessionState)openxr_api->get_session_state();
	}

	return SESSION_STATE_UNKNOWN;
}

/** User Presence. */
bool OpenXRInterface::is_user_presence_supported() const {
	if (openxr_api == nullptr) {
		return false;
	} else if (!openxr_api->is_initialized()) {
		return false;
	} else {
		OpenXRUserPresenceExtension *user_presence_ext = OpenXRUserPresenceExtension::get_singleton();
		if (user_presence_ext == nullptr) {
			return false;
		} else {
			return user_presence_ext->is_active();
		}
	}
}

bool OpenXRInterface::is_user_present() const {
	// If extension is unavailable or unsupported, we default to user is present.
	if (!is_user_presence_supported()) {
		return true;
	} else {
		OpenXRUserPresenceExtension *user_presence_ext = OpenXRUserPresenceExtension::get_singleton();
		return user_presence_ext->is_user_present();
	}
}

/** Hand tracking. */
void OpenXRInterface::set_motion_range(const Hand p_hand, const HandMotionRange p_motion_range) {
	ERR_FAIL_INDEX(p_hand, HAND_MAX);
	ERR_FAIL_INDEX(p_motion_range, HAND_MOTION_RANGE_MAX);


Review comment (bug):
```suggestion
	if (openxr_api == nullptr || !openxr_api->is_initialized()) {
		return false;
```

Code after:
			mode = XR_PLAY_AREA_UNKNOWN;
			break;
	}

	print_verbose("OpenXR Interface: Play area changed, emitting signal.");
	emit_signal(SNAME("play_area_changed"), mode);
}

void OpenXRInterface::on_refresh_rate_changes(float p_new_rate) {
	emit_signal(SNAME("refresh_rate_changed"), p_new_rate);
}

OpenXRInterface::SessionState OpenXRInterface::get_session_state() {
	if (openxr_api) {
		return (SessionState)openxr_api->get_session_state();
	}

	return SESSION_STATE_UNKNOWN;
}

/** User Presence. */
bool OpenXRInterface::is_user_presence_supported() const {
	if (!openxr_api || !openxr_api->is_initialized()) {
		return false;
	} else {
		OpenXRUserPresenceExtension *user_presence_ext = OpenXRUserPresenceExtension::get_singleton();
		return user_presence_ext && user_presence_ext->is_active();
	}
}

bool OpenXRInterface::is_user_present() const {
	// If extension is unavailable or unsupported, we default to user is present.
	if (!is_user_presence_supported()) {
		return true;
	} else {
		OpenXRUserPresenceExtension *user_presence_ext = OpenXRUserPresenceExtension::get_singleton();
		return user_presence_ext->is_user_present();
	}
}

/** Hand tracking. */
void OpenXRInterface::set_motion_range(const Hand p_hand, const HandMotionRange p_motion_range) {
	ERR_FAIL_INDEX(p_hand, HAND_MAX);
	ERR_FAIL_INDEX(p_motion_range, HAND_MOTION_RANGE_MAX);

	OpenXRHandTrackingExtension *hand_tracking_ext = OpenXRHandTrackingExtension::get_singleton();
	if (hand_tracking_ext && hand_tracking_ext->get_active()) {
		XrHandJointsMotionRangeEXT xr_motion_range;
		switch (p_motion_range) {
			case HAND_MOTION_RANGE_UNOBSTRUCTED:
				xr_motion_range = XR_HAND_JOINTS_MOTION_RANGE_UNOBSTRUCTED_EXT;