by mh » Thu Jan 26, 2012 10:46 pm
This one's just come up with RMQ and is worth sharing.
I suspect that the commonly-used R_LightPoint (strictly speaking, RecursiveLightPoint) "enhanced to interpolate lighting" code is both broken and - potentially - dangerous.
First of all, broken because it can sample from up to 3 points outside of the surface's lightmap data. These would be the 3 points in the lightmap data for the next surface according to the order in which light.exe built the data (in some cases - if the next surface's smax * tmax was lower than the current surface's smax, it may even go beyond that and into the one after). This became obvious when we recently moved to RGB10 lightmaps and LIT files (for 4x the dynamic range of traditional lightmaps) and compiled some test maps - lighting on models as they moved (particularly noticeable with the gun) began to get really really weird, with sudden ultra-bright flashes.
Dangerous because 1 or more of those 3 points may go off the end of the loadmodel->lightdata buffer. With Hunk_Alloc you'll just read into the memory for whatever was allocated next, if you're using a different allocator you may crash.