Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix balloon focus issues for controls with no separation

Ricardo Subtil05debbb4f7af
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 4c9726fd1bc..ff15bd941e3 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -3607,6 +3607,13 @@ real_t Control::_focus_strategy_balloon_candidate_score(const Vector2 &p_start,
}
Vector2 hit = touch - p_start;
+
+ // If the hit vector is zero, then the next control's border coincides with ours. In this case
+ // return maximum score instead, to prevent NaN from division by zero
+ if (hit.is_zero_approx()) {
+ return 1.0;
+ }
+
return p_dir.dot(hit) / hit.length_squared();
}