diff options
author | Daniel Castellanos <decacis@gmail.com> | 2023-10-03 16:07:45 -0600 |
---|---|---|
committer | Daniel Castellanos <decacis@gmail.com> | 2023-10-05 01:34:51 -0600 |
commit | 771ec958af3a6ff0d0a9183b0ab7c73d98d8b953 (patch) | |
tree | e8ebe7ecc807634c77080af486db22c2ed92e723 /modules/openxr/openxr_api.cpp | |
parent | f5696c311cdb09e0a34fa4ba7ef5d2524c515b89 (diff) | |
download | redot-engine-771ec958af3a6ff0d0a9183b0ab7c73d98d8b953.tar.gz |
Fixing incorrect swapchain release timing
Applied a couple of checks suggested by @dhoverml for when the
XrResult is not XR_SUCCESS but is also not a failure. Also simplified
checks from @BastiaanOlij feedback.
Diffstat (limited to 'modules/openxr/openxr_api.cpp')
-rw-r--r-- | modules/openxr/openxr_api.cpp | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index b1c7ab1615..d0e958164d 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -1683,14 +1683,27 @@ bool OpenXRAPI::acquire_image(OpenXRSwapChainInfo &p_swapchain) { ERR_FAIL_COND_V(p_swapchain.image_acquired, true); // This was not released when it should be, error out and reuse... XrResult result; - XrSwapchainImageAcquireInfo swapchain_image_acquire_info = { - XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO, // type - nullptr // next - }; - result = xrAcquireSwapchainImage(p_swapchain.swapchain, &swapchain_image_acquire_info, &p_swapchain.image_index); - if (XR_FAILED(result)) { - print_line("OpenXR: failed to acquire swapchain image [", get_error_string(result), "]"); - return false; + + if (!p_swapchain.skip_acquire_swapchain) { + XrSwapchainImageAcquireInfo swapchain_image_acquire_info = { + XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO, // type + nullptr // next + }; + + result = xrAcquireSwapchainImage(p_swapchain.swapchain, &swapchain_image_acquire_info, &p_swapchain.image_index); + if (!XR_UNQUALIFIED_SUCCESS(result)) { + // Make sure end_frame knows we need to submit an empty frame + frame_state.shouldRender = false; + + if (XR_FAILED(result)) { + // Unexpected failure, log this! + print_line("OpenXR: failed to acquire swapchain image [", get_error_string(result), "]"); + return false; + } else { + // In this scenario we silently fail, the XR runtime is simply not ready yet to acquire the swapchain. + return false; + } + } } XrSwapchainImageWaitInfo swapchain_image_wait_info = { @@ -1700,9 +1713,21 @@ bool OpenXRAPI::acquire_image(OpenXRSwapChainInfo &p_swapchain) { }; result = xrWaitSwapchainImage(p_swapchain.swapchain, &swapchain_image_wait_info); - if (XR_FAILED(result)) { - print_line("OpenXR: failed to wait for swapchain image [", get_error_string(result), "]"); - return false; + if (!XR_UNQUALIFIED_SUCCESS(result)) { + // Make sure end_frame knows we need to submit an empty frame + frame_state.shouldRender = false; + + if (XR_FAILED(result)) { + // Unexpected failure, log this! + print_line("OpenXR: failed to wait for swapchain image [", get_error_string(result), "]"); + return false; + } else { + // Make sure to skip trying to acquire the swapchain image in the next frame + p_swapchain.skip_acquire_swapchain = true; + return false; + } + } else { + p_swapchain.skip_acquire_swapchain = false; } return true; |