Skip to content

Commit

Permalink
WebXR - Fixed bug where the wrong number of views is being added (#5063)
Browse files Browse the repository at this point in the history
* Fixed bug where the number of XR views to add was changing

* Replaced with while loop

* Removed if statements from review feedback

---------

Co-authored-by: Steven Yau <syau@snapchat.com>
  • Loading branch information
2 people authored and slimbuck committed Feb 20, 2023
1 parent 638f927 commit 8d1a2c4
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions src/framework/xr/xr-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,32 +694,28 @@ class XrManager extends EventHandler {
const lengthOld = this.views.length;
const lengthNew = pose.views.length;

if (lengthNew > this.views.length) {
// add new views into list
for (let i = 0; i <= (lengthNew - this.views.length); i++) {
let view = this.viewsPool.pop();
if (!view) {
view = {
viewport: new Vec4(),
projMat: new Mat4(),
viewMat: new Mat4(),
viewOffMat: new Mat4(),
viewInvMat: new Mat4(),
viewInvOffMat: new Mat4(),
projViewOffMat: new Mat4(),
viewMat3: new Mat3(),
position: new Float32Array(3),
rotation: new Quat()
};
}

this.views.push(view);
}
} else if (lengthNew <= this.views.length) {
// remove views from list into pool
for (let i = 0; i < (this.views.length - lengthNew); i++) {
this.viewsPool.push(this.views.pop());
while (lengthNew > this.views.length) {
let view = this.viewsPool.pop();
if (!view) {
view = {
viewport: new Vec4(),
projMat: new Mat4(),
viewMat: new Mat4(),
viewOffMat: new Mat4(),
viewInvMat: new Mat4(),
viewInvOffMat: new Mat4(),
projViewOffMat: new Mat4(),
viewMat3: new Mat3(),
position: new Float32Array(3),
rotation: new Quat()
};
}

this.views.push(view);
}
// remove views from list into pool
while (lengthNew < this.views.length) {
this.viewsPool.push(this.views.pop());
}

// reset position
Expand Down

0 comments on commit 8d1a2c4

Please sign in to comment.