Skip to content

Commit 9fc8dd6

Browse files
committed
WebXR: Better errors when WebXR Layers or multiview are unavailable
1 parent 26df043 commit 9fc8dd6

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

modules/webxr/native/library_godot_webxr.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const GodotWebXR = {
9494
return layer;
9595
}
9696

97-
if (!GodotWebXR.session || !GodotWebXR.gl_binding) {
97+
if (!GodotWebXR.session || !GodotWebXR.gl_binding || !GodotWebXR.gl_binding.createProjectionLayer) {
9898
return null;
9999
}
100100

@@ -293,10 +293,29 @@ const GodotWebXR = {
293293
GodotWebXR.gl = gl;
294294

295295
gl.makeXRCompatible().then(function () {
296-
GodotWebXR.gl_binding = new XRWebGLBinding(session, gl);
296+
const throwNoWebXRLayersError = () => {
297+
throw new Error('This browser doesn\'t support WebXR Layers (which Godot requires) nor is the polyfill in use. If you are the developer of this application, please consider including the polyfill.');
298+
};
299+
300+
try {
301+
GodotWebXR.gl_binding = new XRWebGLBinding(session, gl);
302+
} catch (error) {
303+
// We'll end up here for browsers that don't have XRWebGLBinding at all, or if the browser does support WebXR Layers,
304+
// but is using the WebXR polyfill, so calling native XRWebGLBinding with the polyfilled XRSession won't work.
305+
throwNoWebXRLayersError();
306+
}
307+
308+
if (!GodotWebXR.gl_binding.createProjectionLayer) {
309+
// On other browsers, XRWebGLBinding exists and works, but it doesn't support creating projection layers (which is
310+
// contrary to the spec, which says this MUST be supported) and so the polyfill is required.
311+
throwNoWebXRLayersError();
312+
}
297313

298314
// This will trigger the layer to get created.
299-
GodotWebXR.getLayer();
315+
const layer = GodotWebXR.getLayer();
316+
if (!layer) {
317+
throw new Error('Unable to create WebXR Layer.');
318+
}
300319

301320
function onReferenceSpaceSuccess(reference_space, reference_space_type) {
302321
GodotWebXR.space = reference_space;

modules/webxr/webxr_interface_js.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,17 @@ bool WebXRInterfaceJS::initialize() {
291291

292292
if (!initialized) {
293293
if (!godot_webxr_is_supported()) {
294+
emit_signal("session_failed", "WebXR is unsupported by this web browser.");
295+
return false;
296+
}
297+
298+
if (session_mode == "immersive-vr" && !GLES3::Config::get_singleton()->multiview_supported) {
299+
emit_signal("session_failed", "Stereo rendering in Godot requires multiview, but this web browser doesn't support it.");
294300
return false;
295301
}
296302

297303
if (requested_reference_space_types.is_empty()) {
304+
emit_signal("session_failed", "No reference spaces were requested.");
298305
return false;
299306
}
300307

0 commit comments

Comments
 (0)