From baed4bb16082798aef3c089e1d049c735fac3999 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 2 Dec 2022 10:12:54 +0900 Subject: [PATCH] [gl] Skip lights that are too far from the surface Where too far is 1024 units as that is the maximum supported, or the radius. The change to using unsigned for the distances meant the simple checks missed the effective max dist going negative, thus leading to a segfault. --- libs/video/renderer/gl/gl_lightmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/video/renderer/gl/gl_lightmap.c b/libs/video/renderer/gl/gl_lightmap.c index 3d7b3631b..4bbcd40b0 100644 --- a/libs/video/renderer/gl/gl_lightmap.c +++ b/libs/video/renderer/gl/gl_lightmap.c @@ -119,6 +119,8 @@ R_AddDynamicLights_1 (const vec4f_t *transform, msurface_t *surf) VectorSubtract (r_dlights[lnum].origin, entorigin, local); dist = DotProduct (local, surf->plane->normal) - surf->plane->dist; + if (dist > min (1024, r_dlights[lnum].radius)) + continue; VectorMultSub (r_dlights[lnum].origin, dist, surf->plane->normal, impact); @@ -150,7 +152,7 @@ R_AddDynamicLights_1 (const vec4f_t *transform, msurface_t *surf) if (td < maxdist3) { // ensure part is visible on this line maxdist2 = maxdist - td; for (s = 0; s < smax; s++) { - if (sdtable[s] < maxdist2) { + if (sdtable[s] + td < maxdist2) { j = dlightdivtable[(sdtable[s] + td) >> 7]; *bl++ += (grey * j) >> 7; } else @@ -189,6 +191,8 @@ R_AddDynamicLights_3 (const vec4f_t *transform, msurface_t *surf) VectorSubtract (r_dlights[lnum].origin, entorigin, local); dist = DotProduct (local, surf->plane->normal) - surf->plane->dist; + if (dist > min (1024, r_dlights[lnum].radius)) + continue; VectorMultSub (r_dlights[lnum].origin, dist, surf->plane->normal, impact); @@ -221,7 +225,7 @@ R_AddDynamicLights_3 (const vec4f_t *transform, msurface_t *surf) if (td < maxdist3) { // ensure part is visible on this line maxdist2 = maxdist - td; for (s = 0; s < smax; s++) { - if (sdtable[s] < maxdist2) { + if (sdtable[s] + td < maxdist2) { j = dlightdivtable[(sdtable[s] + td) >> 7]; *bl++ += (red * j) >> 7; *bl++ += (green * j) >> 7;