Skip to content

Conversation

@wsmlby
Copy link
Contributor

@wsmlby wsmlby commented Sep 16, 2025

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:

    float start[2] = {0, 0};
    float end[2] = {30, 2};
    float cur[2] = {0, 0};
    for(; is_pixel_in_line(cur, start, end); next_pixel_in_line(cur, start, end)) {
        printf("%f, %f\n", cur[0], cur[1]);
    }

This PR fixed it.

@sysrsbuild
Copy link
Contributor

Can one of the admins verify this patch?

@wsmlby
Copy link
Contributor Author

wsmlby commented Sep 16, 2025

Another option here is to make is_pixel_in_line exclusive on the end side.

@Nir-Az Nir-Az requested a review from Copilot September 18, 2025 09:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]) {
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@Nir-Az Nir-Az requested a review from OhadMeir September 21, 2025 11:23
@OhadMeir OhadMeir closed this Sep 21, 2025
@OhadMeir OhadMeir reopened this Sep 21, 2025
@OhadMeir
Copy link
Contributor

Close and reopen to trigger internal CI

@Nir-Az Nir-Az merged commit aa6db1d into realsenseai:development Sep 25, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants