From 3c414347a82d52139aa5473e15d0b9e9242f5f9e Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 30 Jan 2014 02:05:50 +0000 Subject: [PATCH] allow .rtlights files to have style values outside the range 0...MAX_LIGHTSTYLES - in particular, -1 is used by fte for unstyled lights and this is a compatible behavior, just that the loader was getting in the way. for safety the MAX_LIGHTSTYLES comparison has been added to each use of light->style in rendering. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12052 d7cf8633-e32d-0410-b094-e92efae38249 --- r_shadow.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/r_shadow.c b/r_shadow.c index a5f34d5b..2985a6d7 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -2651,7 +2651,7 @@ void R_Shadow_UpdateBounceGridTexture(void) w = r_shadow_lightintensityscale.value * (rtlight->ambientscale + rtlight->diffusescale + rtlight->specularscale); if (w * VectorLength2(rtlight->color) == 0.0f) continue; - w *= (rtlight->style >= 0 ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1); + w *= ((rtlight->style >= 0 && rtlight->style < MAX_LIGHTSTYLES) ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1); VectorScale(rtlight->color, w, rtlight->photoncolor); //if (!VectorLength2(rtlight->photoncolor)) // continue; @@ -3968,7 +3968,7 @@ static void R_Shadow_PrepareLight(rtlight_t *rtlight) rtlight->currentcubemap = rtlight->cubemapname[0] ? R_GetCubemap(rtlight->cubemapname) : r_texture_whitecube; // look up the light style value at this time - f = (rtlight->style >= 0 ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value; + f = ((rtlight->style >= 0 && rtlight->style < MAX_LIGHTSTYLES) ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value; VectorScale(rtlight->color, f, rtlight->currentcolor); /* if (rtlight->selected) @@ -4629,7 +4629,7 @@ void R_Shadow_PrepareLights(int fbo, rtexture_t *depthtexture, rtexture_t *color for (lnum = 0;lnum < r_refdef.scene.numlights;lnum++) { rtlight_t *rtlight = r_refdef.scene.lights[lnum]; - f = (rtlight->style >= 0 ? r_refdef.scene.lightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value; + f = ((rtlight->style >= 0 && rtlight->style < MAX_LIGHTSTYLES) ? r_refdef.scene.lightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value; VectorScale(rtlight->color, f, rtlight->currentcolor); } } @@ -5343,12 +5343,10 @@ static dlight_t *R_Shadow_NewWorldLight(void) static void R_Shadow_UpdateWorldLight(dlight_t *light, vec3_t origin, vec3_t angles, vec3_t color, vec_t radius, vec_t corona, int style, int shadowenable, const char *cubemapname, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags) { matrix4x4_t matrix; + + // note that style is no longer validated here, -1 is used for unstyled lights and >= MAX_LIGHTSTYLES is accepted for sake of editing rtlights files that might be out of bounds but perfectly formatted + // validate parameters - if (style < 0 || style >= MAX_LIGHTSTYLES) - { - Con_Printf("R_Shadow_NewWorldLight: invalid light style number %i, must be >= 0 and < %i\n", light->style, MAX_LIGHTSTYLES); - style = 0; - } if (!cubemapname) cubemapname = ""; -- 2.39.2