The open source OpenXR runtime
0
fork

Configure Feed

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

a/util: Fix edge cases in Moses's distortion method

Before this, we read out of bounds at the bottom of the display. Unsure why nothing but Valgrind caught it.

authored by

Moses Turner and committed by
Moses Turner
dcbdcede bb752819

+26 -6
+26 -6
src/xrt/auxiliary/util/u_distortion_mesh.c
··· 342 342 float v_index_frac = (v * v_edge_num) - v_index_int; 343 343 344 344 // Imagine this like a ray coming out of your eye with x, y coordinate bearing and z coordinate -1.0f 345 - struct xrt_vec2 bearing; 345 + struct xrt_vec2 bearing = {0}; 346 346 347 347 int stride = values->num_grid_points_u; 348 348 349 + float eps = 0.000001; 349 350 350 - if (u_index_frac > 0.000001 || v_index_frac > 0.000001) { 351 + struct xrt_vec2 *grid = values->grid[view]; 352 + int topleft_i = (v_index_int * stride) + u_index_int; 353 + int topright_i = (v_index_int * stride) + u_index_int + 1; 354 + int bottomleft_i = ((v_index_int + 1) * stride) + u_index_int; 355 + int bottomright_i = ((v_index_int + 1) * stride) + u_index_int + 1; 356 + 357 + if (u_index_frac > eps && v_index_frac > eps) { 358 + // Usual case - we're in the middle of a cell 351 359 // {top,bottom}-{left,right} notation might be inaccurate. The code *works* right now but don't take its 352 360 // word when reading 353 - struct xrt_vec2 topleft = values->grid[view][(v_index_int * stride) + u_index_int]; 354 - struct xrt_vec2 topright = values->grid[view][(v_index_int * stride) + u_index_int + 1]; 355 - struct xrt_vec2 bottomleft = values->grid[view][((v_index_int + 1) * stride) + u_index_int]; 356 - struct xrt_vec2 bottomright = values->grid[view][((v_index_int + 1) * stride) + u_index_int + 1]; 361 + struct xrt_vec2 topleft = grid[topleft_i]; 362 + struct xrt_vec2 topright = grid[topright_i]; 363 + struct xrt_vec2 bottomleft = grid[bottomleft_i]; 364 + struct xrt_vec2 bottomright = grid[bottomright_i]; 365 + 357 366 struct xrt_vec2 left_point_on_line_segment = m_vec2_lerp(topleft, bottomleft, v_index_frac); 358 367 struct xrt_vec2 right_point_on_line_segment = m_vec2_lerp(topright, bottomright, v_index_frac); 359 368 360 369 bearing = m_vec2_lerp(left_point_on_line_segment, right_point_on_line_segment, u_index_frac); 370 + 371 + } else if (v_index_frac > eps) { 372 + // We're on a vertical edge 373 + struct xrt_vec2 top = values->grid[view][topleft_i]; 374 + struct xrt_vec2 bottom = values->grid[view][bottomleft_i]; 375 + bearing = m_vec2_lerp(top, bottom, v_index_frac); 376 + } else if (u_index_frac > eps) { 377 + // We're on a horizontal edge 378 + struct xrt_vec2 left = values->grid[view][topleft_i]; 379 + struct xrt_vec2 right = values->grid[view][topright_i]; 380 + bearing = m_vec2_lerp(left, right, u_index_frac); 361 381 } else { 362 382 int acc_idx = (v_index_int * stride) + u_index_int; 363 383 bearing = values->grid[view][acc_idx];