The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

st/oxr: Fix crash and tidy depth layer code

This fixes a crash when XR_KHR_composition_layer_depth is disabled.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2406>

+25 -24
+25 -24
src/xrt/state_trackers/oxr/oxr_session_frame_end.c
··· 1 1 // Copyright 2018-2021, Collabora, Ltd. 2 + // Copyright 2024-2025, NVIDIA CORPORATION. 2 3 // SPDX-License-Identifier: BSL-1.0 3 4 /*! 4 5 * @file ··· 1296 1297 uint64_t xrt_timestamp) 1297 1298 { 1298 1299 struct oxr_space *spc = XRT_CAST_OXR_HANDLE_TO_PTR(struct oxr_space *, proj->space); 1299 - struct oxr_swapchain *d_scs[XRT_MAX_VIEWS] = {0}; 1300 1300 struct oxr_swapchain *scs[XRT_MAX_VIEWS] = {0}; 1301 1301 struct xrt_pose *pose_ptr = NULL; 1302 1302 struct xrt_pose pose[XRT_MAX_VIEWS] = {0}; 1303 1303 struct xrt_swapchain *swapchains[XRT_MAX_VIEWS] = {0}; 1304 + 1304 1305 #ifdef OXR_HAVE_KHR_composition_layer_depth 1306 + // Number of depth layers must be 0 or proj->viewCount. 1307 + bool d_scs_valid = true; 1308 + struct oxr_swapchain *d_scs[XRT_MAX_VIEWS] = {0}; 1305 1309 struct xrt_swapchain *d_swapchains[XRT_MAX_VIEWS] = {0}; 1306 - #endif 1310 + #else 1311 + const bool d_scs_valid = false; 1312 + #endif // OXR_HAVE_KHR_composition_layer_depth 1307 1313 1308 1314 enum xrt_layer_composition_flags flags = convert_layer_flags(proj->layerFlags); 1309 1315 ··· 1341 1347 fill_in_layer_settings(sess, (XrCompositionLayerBaseHeader *)proj, &data); 1342 1348 1343 1349 #ifdef OXR_HAVE_KHR_composition_layer_depth 1344 - // number of depth layers must be 0 or proj->viewCount 1345 - const XrCompositionLayerDepthInfoKHR *d_is[XRT_MAX_VIEWS]; 1346 1350 for (uint32_t i = 0; i < proj->viewCount; ++i) { 1347 - d_scs[i] = NULL; 1348 - d_is[i] = OXR_GET_INPUT_FROM_CHAIN(&proj->views[i], XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR, 1349 - XrCompositionLayerDepthInfoKHR); 1350 - if (d_is[i]) { 1351 - data.depth.d[i].far_z = d_is[i]->farZ; 1352 - data.depth.d[i].near_z = d_is[i]->nearZ; 1353 - data.depth.d[i].max_depth = d_is[i]->maxDepth; 1354 - data.depth.d[i].min_depth = d_is[i]->minDepth; 1355 - struct oxr_swapchain *sc = 1356 - XRT_CAST_OXR_HANDLE_TO_PTR(struct oxr_swapchain *, d_is[i]->subImage.swapchain); 1357 - fill_in_sub_image(sc, &d_is[i]->subImage, &data.depth.d[i].sub); 1358 - d_scs[i] = sc; 1359 - d_swapchains[i] = sc->swapchain; 1351 + const XrCompositionLayerDepthInfoKHR *d_info = OXR_GET_INPUT_FROM_CHAIN( 1352 + &proj->views[i], XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR, XrCompositionLayerDepthInfoKHR); 1353 + 1354 + if (d_info == NULL) { 1355 + d_scs_valid = false; 1356 + break; // It's all or nothing. 1360 1357 } 1358 + 1359 + data.depth.d[i].far_z = d_info->farZ; 1360 + data.depth.d[i].near_z = d_info->nearZ; 1361 + data.depth.d[i].max_depth = d_info->maxDepth; 1362 + data.depth.d[i].min_depth = d_info->minDepth; 1363 + struct oxr_swapchain *sc = 1364 + XRT_CAST_OXR_HANDLE_TO_PTR(struct oxr_swapchain *, d_info->subImage.swapchain); 1365 + fill_in_sub_image(sc, &d_info->subImage, &data.depth.d[i].sub); 1366 + d_scs[i] = sc; 1367 + d_swapchains[i] = sc->swapchain; 1361 1368 } 1362 1369 #endif // OXR_HAVE_KHR_composition_layer_depth 1363 - bool d_scs_valid = true; 1364 - for (uint32_t i = 0; i < proj->viewCount; i++) { 1365 - if (d_scs[i] == NULL) { 1366 - d_scs_valid = false; 1367 - break; 1368 - } 1369 - } 1370 + 1370 1371 if (d_scs_valid) { 1371 1372 #ifdef OXR_HAVE_KHR_composition_layer_depth 1372 1373 fill_in_depth_test(sess, (XrCompositionLayerBaseHeader *)proj, &data);