diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-01-28 09:32:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-28 09:32:19 +0100 |
commit | b441592372197499d6f618c02bad2e79e23fc238 (patch) | |
tree | d3239404e722578be9eb7528fa03aa5ddbbf5ce8 /modules/webxr/webxr_interface_js.cpp | |
parent | 1ea133b6b58a4cf4ba5c077095a5b59266bac8e4 (diff) | |
parent | a23fc126eb0ea93e0ca8e622586649404e6f668e (diff) |
Merge pull request #45514 from dsnopek/webxr-master-ar-lose-tracking
Prevent fatal error in WebXR when 'immersize-ar' loses and regains tracking
Diffstat (limited to 'modules/webxr/webxr_interface_js.cpp')
-rw-r--r-- | modules/webxr/webxr_interface_js.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 7cfaf31495..74789fc98e 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -78,6 +78,8 @@ void _emwebxr_on_session_failed(char *p_message) { Ref<XRInterface> interface = xr_server->find_interface("WebXR"); ERR_FAIL_COND(interface.is_null()); + interface->uninitialize(); + String message = String(p_message); interface->emit_signal("session_failed", message); } @@ -224,6 +226,12 @@ bool WebXRInterfaceJS::initialize() { // make this our primary interface xr_server->set_primary_interface(this); + // Clear render_targetsize to make sure it gets reset to the new size. + // Clearing in uninitialize() doesn't work because a frame can still be + // rendered after it's called, which will fill render_targetsize again. + render_targetsize.width = 0; + render_targetsize.height = 0; + initialized = true; godot_webxr_initialize( @@ -277,22 +285,24 @@ Transform WebXRInterfaceJS::_js_matrix_to_transform(float *p_js_matrix) { } Size2 WebXRInterfaceJS::get_render_targetsize() { - Size2 target_size; + if (render_targetsize.width != 0 && render_targetsize.height != 0) { + return render_targetsize; + } int *js_size = godot_webxr_get_render_targetsize(); if (!initialized || js_size == nullptr) { - // As a default, use half the window size. - target_size = DisplayServer::get_singleton()->window_get_size(); - target_size.width /= 2.0; - return target_size; + // As a temporary default (until WebXR is fully initialized), use half the window size. + Size2 temp = DisplayServer::get_singleton()->window_get_size(); + temp.width /= 2.0; + return temp; } - target_size.width = js_size[0]; - target_size.height = js_size[1]; + render_targetsize.width = js_size[0]; + render_targetsize.height = js_size[1]; free(js_size); - return target_size; + return render_targetsize; }; Transform WebXRInterfaceJS::get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) { |