Commit cffc2693 authored by Jacob DeWitt's avatar Jacob DeWitt Committed by Commit Bot

Prevent WebXR controller from getting stuck when headset is removed.

When using a Daydream controller with a Mirage headset, the controller
position and orientation would get stuck when taking the headset off
and putting it back on. Doing so fires an input state change event which
causes the XRInputSource to be re-created. The copy constructor for
XRInputSource did a shallow copy of its grip and target ray spaces which
meant they still point to the old XRInputSource object which no longer
is exposed to the webpage or receives updates via mojo.

Fix this by making the XRInputSource copy constructor create new
target ray and grip space objects that point to the new XRInputSource
object.

Bug: 968544
Change-Id: I33542bde17bac70d57569bcdcce4a0206d8f45ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637239
Commit-Queue: Jacob DeWitt <jacde@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664963}
parent 1c25ddce
......@@ -132,15 +132,19 @@ XRInputSource::XRInputSource(
}
}
// Deep copy because of the unique_ptrs
// Must make new target_ray_space_ and grip_space_ to ensure that they point to
// the correct XRInputSource object. Otherwise, the controller position gets
// stuck when an XRInputSource gets re-created. Also need to make a deep copy of
// the matrices since they use unique_ptrs.
XRInputSource::XRInputSource(const XRInputSource& other)
: active_frame_id_(other.active_frame_id_),
primary_input_pressed_(other.primary_input_pressed_),
selection_cancelled_(other.selection_cancelled_),
session_(other.session_),
source_id_(other.source_id_),
target_ray_space_(other.target_ray_space_),
grip_space_(other.grip_space_),
target_ray_space_(
MakeGarbageCollected<XRTargetRaySpace>(other.session_, this)),
grip_space_(MakeGarbageCollected<XRGripSpace>(other.session_, this)),
gamepad_(other.gamepad_),
emulated_position_(other.emulated_position_),
base_timestamp_(other.base_timestamp_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment