godotengine / godotengine/godot

Curve2D get_closest_offset always returns zero if first two points in curve are the same

Open
#94,872 2 comments 0 reactions 0 assignees View on GitHub
bug topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Discovered in v4.3.rc1.official [e343dbbcc]
- Reproduced in v4.2.stable.official [46dc27791]

### System information

Godot v4.3.rc1 - Windows 10.0.22631 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1060 3GB (NVIDIA; 31.0.15.5176) - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)

### Issue description

If a Curve2D has the same position for the first two points, `get_closest_offset` always returns zero, instead of returning the correct offset. With the same curve, if I remove one of the first duplicate points it then returns the correct offset.

### Steps to reproduce

Example code:
```
var curve := Curve2D.new()
curve.add_point(Vector2(100, 100))
curve.add_point(Vector2(100, 100))
curve.add_point(Vector2(200, 200))
var result = curve.get_closest_offset(Vector2(200, 200))
```

1. Run the code, and confirm result incorrectly returns zero (should return ~141)
2. Comment out the third line, thus making the first two points not the same
3. Run the code again, and confirm the result returns the correct offset.

### Minimal reproduction project (MRP)

[curve2doffsettest.zip](https://github.com/user-attachments/files/16403003/curve2doffsettest.zip)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the Curve2D example from the report and compare get_closest_offset with and without the duplicate first point. Trace the Curve2D implementation and its closest-offset tests, then confirm that a curve with duplicate initial points returns the expected offset of about 141 rather than zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, godot
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.