immersive-web / webxr-samples

Samples to demonstrate use of the WebXR Device API
https://immersive-web.github.io/webxr-samples/
MIT License
979 stars 474 forks source link

WebXR samples renderer issue #166

Open cabanier opened 12 months ago

cabanier commented 12 months ago

We found an issue with the renderer that is bespoke to the sample repo. When re-entering a WebXR session and creating a new renderer, some node will stop rendering.

This can be seen in immersive-hands.html. If you enter, exit and re-enter, the spinning cube in the middle will stop rendering. This is happening because starting a session will create a new renderer which will run the following code:

  _setRenderer(renderer) {
    if (this._renderer == renderer) {
      return;
    }

    if (this._renderer) {
      // Changing the renderer removes any previously attached renderPrimitives
      // from a different renderer.
      this.clearRenderPrimitives(); <-------------
    }

    this._renderer = renderer;
    if (renderer) {
      this.onRendererChanged(renderer);

      for (let child of this.children) {
        child._setRenderer(renderer);
      }
    }
  }

After this, the objects have no more render primitives and will no longer draw. @toji , do you have thoughts about this? Should this be fixed in the renderer or can we make it so we reuse the renderer?