Skip to content

Coordinate flip in Picking.js causes out-of-bounds access when y=0 #12751

@gilgilad

Description

@gilgilad

What happened?

Hello ,
In the pickPositionWorldCoordinates function at line 632:

drawingBufferPosition.y = scene.drawingBufferHeight - drawingBufferPosition.y;

There is a Y-coordinate flip:
drawingBufferPosition.y = scene.drawingBufferHeight - drawingBufferPosition.y;

However, this creates an off-by-one error. When drawingBufferPosition.y = 0, the result becomes scene.drawingBufferHeight, which is out of bounds since valid pixel coordinates should range from [0, scene.drawingBufferHeight - 1].
For example, with a drawing buffer height of 270:

Input: y = 0 → Output: y = 270 (invalid - should be 269)
Input: y = 269 → Output: y = 1 (valid)

Should this be corrected to:
drawingBufferPosition.y = scene.drawingBufferHeight - drawingBufferPosition.y - 1

This would ensure the coordinate stays within valid bounds [0, height-1] after the flip.
Is this intentional behavior, or should it be fixed?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions