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

Race condition in component updates #19

Closed
bryik opened this issue May 10, 2020 · 0 comments · Fixed by #18
Closed

Race condition in component updates #19

bryik opened this issue May 10, 2020 · 0 comments · Fixed by #18
Labels
Milestone

Comments

@bryik
Copy link
Owner

bryik commented May 10, 2020

Rapidly changing the folder property causes unpredictable behaviour.

<a-scene>
  <a-entity id="skybox" cubemap="folder: /assets/Yokohama3/"></a-entity>
</a-scene>
<script type="text/javascript">
  setTimeout(changeBackground, 2000);

  function changeBackground() {
    let skybox = document.querySelector("#skybox");
    skybox.setAttribute("cubemap", "folder: /assets/GoldenGateBridge2/");
    skybox.setAttribute("cubemap", "folder: /assets/Yokohama3/");
    // Which cubemap will be displayed?
  }
</script>

The cubemap that ultimately gets displayed depends on the order texture load callbacks are executed which is random. It is quite easy to end up in situations where component data is inconsistent with the displayed texture:

image

In the above, /assets/GoldenGateBridge2/" is displayed, but data.folder is "/assets/Yokohama3/".

Proposed fix

The texture load callback is closed over the original folder path it was called to load (srcPath) and can be given access to the current component data by binding this. By comparing past and current folder paths, the texture load callback can figure out what to do.

// Within the texture load callback
if (srcPath !== this.data.folder) {
  // The texture that just finished loading no longer matches the folder
  // set on this component.
  texture.dispose();
  return;
}
// The folder property has not changed, so go ahead with the texture update.
@bryik bryik added the bug label May 10, 2020
bryik added a commit that referenced this issue May 10, 2020
Issue described in:
#19
@bryik bryik added this to the v2.0.0 milestone May 10, 2020
@bryik bryik linked a pull request May 10, 2020 that will close this issue
@bryik bryik closed this as completed in #18 May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant