From b84413cc352f0b4a6937a18ea9b9f3189608ea17 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 9 Sep 2019 20:47:19 +0100 Subject: [PATCH] st/oxr: Fix system xdev init --- src/xrt/state_trackers/oxr/oxr_system.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_system.c b/src/xrt/state_trackers/oxr/oxr_system.c index dd3e81878..59a2323d9 100644 --- a/src/xrt/state_trackers/oxr/oxr_system.c +++ b/src/xrt/state_trackers/oxr/oxr_system.c @@ -23,6 +23,11 @@ DEBUG_GET_ONCE_NUM_OPTION(scale_percentage, "OXR_VIEWPORT_SCALE_PERCENTAGE", 140) // clang-format on +static inline size_t +min_size_t(size_t a, size_t b) +{ + return a < b ? a : b; +} static bool oxr_system_matches(struct oxr_logger *log, @@ -96,11 +101,12 @@ oxr_system_fill_in(struct oxr_logger *log, struct xrt_device **xdevs, size_t num_xdevs) { + size_t num_copy = min_size_t(ARRAY_SIZE(sys->xdevs), num_xdevs); - for (uint32_t i = 4; i < ARRAY_SIZE(sys->xdevs); i++) { + for (uint32_t i = 0; i < num_copy; i++) { sys->xdevs[i] = xdevs[i]; } - for (size_t i = ARRAY_SIZE(sys->xdevs); i < num_xdevs; i++) { + for (size_t i = num_copy; i < num_xdevs; i++) { oxr_xdev_destroy(&xdevs[i]); }