GL Context Lost – preventDefault

Description of the problem

The updated WebVR 1.1 specification has provisions for multi-GPU systems, which rely on correct usage of the webglcontextlost and webglcontextrestored events, or, the page not handling the events at all.

  • note, that due to a documentation build issue, you may need to look at the source spec bikeshed file – search for ‘context will be lost‘.

Currently three.js handles the event webglcontextlost, calling event.preventDefault to inform the browser that it intends to handle the webglcontextrestored event, yet makes no attempt to rebuild the resources (nor handle that event). Further, resetGLState(), setDefaultGLState() etc should actually occur in a webglcontextrestored.

Until such a time as three.js can confidently handle the webglcontextrestored event (such as building on the method proposed in issue #5507) handling of context lost should be removed entirely – or at the very least, not make a call to event.preventDefault() in the event handler.

From three.js WebGLRenderer.js:538

	function onContextLost( event ) {
		// LW: Remove this until glcontextrestored is handled correctly
		event.preventDefault();

		// LW: Below here should actually be in glcontextrestored
		resetGLState();
		setDefaultGLState();

		properties.clear();
		objects.clear();

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

Multi GPU system (such as a laptop, or a machine with motherboard integrated graphics and a discrete adapter)
VR Headset plugged in to discrete GPU
Monitor plugged in to integrated motherboard graphics

Author: Fantashit

1 thought on “GL Context Lost – preventDefault

  1. Okay. Basic support added. Works in most of the cases but a few things break when restored (sprites, lensflares, etc). I’ll be fixing them over the next days.

Comments are closed.