From ce8ad6c3843772976ecc4682ae5726dc70e35bdc Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 15 Jun 2017 13:43:42 -0600 Subject: [PATCH] light: handle iffy faces --- light/ltface.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/light/ltface.cc b/light/ltface.cc index 1dc2b986..61c8bbc2 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -402,6 +402,10 @@ position_t CalcPointNormal(const bsp2_t *bsp, const bsp2_dface_t *face, const qv const auto &points = facecache.points(); const auto &edgeplanes = facecache.edgePlanes(); + // check for degenerate face + if (points.empty() || edgeplanes.empty()) + return position_t(origPoint); + // project `point` onto the surface plane, then lift it off again const qvec3f point = GLM_ProjectPointOntoPlane(surfplane, origPoint) + (qvec3f(surfplane) * sampleOffPlaneDist); @@ -551,7 +555,10 @@ PositionSamplePointOnFace(const bsp2_t *bsp, } const float planedist = GLM_DistAbovePlane(plane, point); - Q_assert(fabs(planedist - sampleOffPlaneDist) <= 0.1); + if (!(fabs(planedist - sampleOffPlaneDist) <= 0.1)) { + // something is wrong? + return position_t(point); + } const float insideDist = GLM_EdgePlanes_PointInsideDist(edgeplanes, point); if (insideDist < -POINT_EQUAL_EPSILON) {