Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebXR - Fixed bug where the wrong number of views is being added #5063

Merged
merged 3 commits into from
Feb 10, 2023

Conversation

yaustar
Copy link
Contributor

@yaustar yaustar commented Feb 9, 2023

Fixes an error in WebXR on some devices that have more than 2 viewports about view being undefined

image

This is because when we add views to an array in the loop, we are also using the length of that array to calculate how many to add which means the total number to add gets smaller each loop.

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@yaustar yaustar added bug area: xr XR related issue labels Feb 9, 2023
@yaustar yaustar requested a review from a team February 9, 2023 16:13
@yaustar yaustar self-assigned this Feb 9, 2023
@yaustar yaustar marked this pull request as ready for review February 9, 2023 16:13
@@ -696,7 +696,8 @@ class XrManager extends EventHandler {

if (lengthNew > this.views.length) {
// add new views into list
for (let i = 0; i <= (lengthNew - this.views.length); i++) {
const viewAddCount = (lengthNew - this.views.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at recently when you were refactoring around there, and though it'd be best to replace the if above as as well as the loop with while (lengthNew > this.views.length) {

and similar for the else / for loop in the else branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I don't have a way of testing the logic in the else branch so can you double check the code please 😅

@yaustar yaustar changed the title Fixed bug where the number of XR views to add was changing WebXR - Fixed bug where the wrong number of views is being added Feb 9, 2023
@@ -696,8 +696,7 @@ class XrManager extends EventHandler {

if (lengthNew > this.views.length) {
// add new views into list
const viewAddCount = (lengthNew - this.views.length);
for (let i = 0; i <= viewAddCount; i++) {
while (lengthNew > this.views.length) {
Copy link
Contributor

@mvaligursky mvaligursky Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now get rid of that if, and also else?
the code should just be

while (..) {
}

while (..) {
}

no need for ifs as they just do the same as the first iteration of the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, looks good.
Personally I'd remove the viewsPool completely as well, I'm not sure we win anything apart from complexity by pooling those objects, I don't expect the count of views changes often / ever.

@yaustar yaustar merged commit 1be6f0b into main Feb 10, 2023
@yaustar yaustar deleted the webxr-fix-view-count branch February 10, 2023 09:32
@Maksims
Copy link
Contributor

Maksims commented Feb 14, 2023

Approving, looks good. Personally I'd remove the viewsPool completely as well, I'm not sure we win anything apart from complexity by pooling those objects, I don't expect the count of views changes often / ever.

As I recall, when session starts views might be not available straight away. Also, they might get removed due to platform specific behaviours (like minimizing or going into passthrough, and can be other edge cases). Then can get available again, and in different order within an array.

Here is the source of specs: https://www.w3.org/TR/webxr/#xrview-interface

No guarantee is made about the number of views any XR device uses or their order, nor is the number of views required to be constant for the duration of an XRSession.

slimbuck pushed a commit that referenced this pull request Feb 20, 2023
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: xr XR related issue bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants