fix potential infinite loop in rs2_project_color_pixel_to_depth_pixel - #14295
Conversation
|
Can one of the admins verify this patch? |
|
Another option here is to make is_pixel_in_line exclusive on the end side. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a potential infinite loop in rs2_project_color_pixel_to_depth_pixel that occurs due to floating point precision issues when iterating along a line between two pixels. The fix adds an explicit check to break the loop when the current pixel position exactly matches the end pixel.
- Adds a safety check to prevent infinite loops caused by floating point precision issues
- Includes explanatory comment documenting the specific scenario that causes the problem
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // this is needed to avoid floating point precision issues when p is equal to end_pixel | ||
| // in this case the next_pixel_in_line can jump back and forth and cause an infinite loop | ||
| // example: start=(0,0), end=(30,2) | ||
| if (p[0] == end_pixel[0] && p[1] == end_pixel[1]) { |
There was a problem hiding this comment.
Using exact floating point equality comparison can be unreliable due to precision issues. Consider using a small epsilon tolerance for the comparison instead, such as fabs(p[0] - end_pixel[0]) < epsilon && fabs(p[1] - end_pixel[1]) < epsilon.
|
Close and reopen to trigger internal CI |
The current implementation of next_pixel_in_line and is_pixel_in_line means a loop may fall into an infinite loop if start/end's Y difference is an integer.
example:
This PR fixed it.