fix(viewport): hide path preview on zero-length input

start == end would call glm::normalize on a zero vector, producing
NaN dir/perp and NaN ribbon vertex positions. Vulkan would either
drop the draw silently or trip a validation error. Hide the preview
when the segment is degenerate.
This commit is contained in:
Kelsi 2026-05-06 07:53:07 -07:00
parent 4babaebf86
commit 130aa34d73

View file

@ -436,7 +436,13 @@ void EditorViewport::setPathPreview(const glm::vec3& start, const glm::vec3& end
struct BV { float pos[3]; float color[4]; };
std::vector<BV> verts;
glm::vec2 dir = glm::normalize(glm::vec2(end.x - start.x, end.y - start.y));
glm::vec2 delta(end.x - start.x, end.y - start.y);
float dlen = glm::length(delta);
// start == end would produce NaN dir/perp from glm::normalize and then
// NaN positions in the path ribbon — Vulkan would either drop the draw
// or crash on validation. Hide the preview instead.
if (dlen < 1e-4f) { pathVisible_ = false; return; }
glm::vec2 dir = delta / dlen;
glm::vec2 perp(-dir.y, dir.x);
float z0 = start.z + 2.0f;
float z1 = end.z + 2.0f;