From 8ba5fa67b85f7c661badc158a491cf34015710b4 Mon Sep 17 00:00:00 2001 From: Tomas Maly Date: Fri, 24 Nov 2023 12:21:47 +0100 Subject: [PATCH] make guiInWorld tolerant to invalid rays --- sources/libsimple/guiInWorld.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sources/libsimple/guiInWorld.cpp b/sources/libsimple/guiInWorld.cpp index 4851239d..ee13d5ac 100644 --- a/sources/libsimple/guiInWorld.cpp +++ b/sources/libsimple/guiInWorld.cpp @@ -43,7 +43,7 @@ namespace cage struct Intersection { - Vec3 wp; // world position + Vec3 wp = Vec3::Nan(); // world position Vec2 gp; // gui position in 0*0 .. w*h bool intersects = false; }; @@ -51,6 +51,8 @@ namespace cage CAGE_FORCE_INLINE Intersection detect(const Line &ray) const { Intersection res; + if (!ray.valid()) + return res; const Transform tr = config.renderEntity->value(); const Plane pl = Plane(tr.position, tr.orientation * Vec3(0, 0, -1)); res.wp = cage::intersection(pl, ray);