Scene memory managment is a bit strange for webvr use cases

Description of the problem

Most webvr experiences are one experience per site, but when you have a site with multiple webvr experiences you can have the case where you have on ThreeJS renderer (i.e. the WebVR renderer) and you just want to use different scenes with it (a new scene for a new webvr experiences). This works but it ends up leaking memory because although you can dispose of the objects in the scene graph, the WebGLRenderer saves state for each scene/camera pair. And it looks like calling dispose on WebGLRenderer makes the renderer invalid afterwards.

You could have one canvas already for WebVR, and then have a new WebGLRenderer for each WebVR experience and just use the same canvas/gl context for each, but there’s a memory hit for this as well and you could have bugs where multiple renderers are trying to draw to the same context (i.e. the one who is actually presenting and then one that wasn’t shut down correctly). Using a singleton for the WebVR renderer is nice as it makes it a bit easier to see who is actually renderering.

Three.js version
  • Dev
  • r99
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

1 thought on “Scene memory managment is a bit strange for webvr use cases

  1. How about introducing Scene.dispose() in order to solve this issue? Similar to WebGLGeometries or WebGLTextures, WebGLRenderStates could add an event listener to the dispose event of a scene. If the event is fired, the respective instance of WebGLRenderState is deleted.

    @joshpatt2 Would something like this be helpful to you?

Comments are closed.