diff options
author | BenjaminRi <28017860+BenjaminRi@users.noreply.github.com> | 2020-08-23 15:39:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-23 15:39:55 +0200 |
commit | f5a203fbcd3af358bc1639467014063ba8409d3e (patch) | |
tree | 9ffc980351cc6c4fc8e61f83fcdc6ac05f66cb6b | |
parent | cf5547227d9fffd9fb0043ce0b5633b831536eb6 (diff) | |
download | minetest-f5a203fbcd3af358bc1639467014063ba8409d3e.tar.gz minetest-f5a203fbcd3af358bc1639467014063ba8409d3e.tar.bz2 minetest-f5a203fbcd3af358bc1639467014063ba8409d3e.zip |
Fix light overflow of u8 if light is saturated at 255 (#10305)
-rw-r--r-- | src/light.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/light.cpp b/src/light.cpp index 8196fedff..d5389b450 100644 --- a/src/light.cpp +++ b/src/light.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "light.h" +#include <algorithm> #include <cmath> #include "util/numeric.h" #include "settings.h" @@ -81,9 +82,11 @@ void set_light_table(float gamma) // Strictly speaking, rangelim is not necessary here—if the implementation // is conforming. But we don’t want problems in any case. light_LUT[i] = rangelim((s32)(255.0f * brightness), 0, 255); + // Ensure light brightens with each level - if (i > 1 && light_LUT[i] <= light_LUT[i - 1]) - light_LUT[i] = light_LUT[i - 1] + 1; + if (i > 0 && light_LUT[i] <= light_LUT[i - 1]) { + light_LUT[i] = std::min((u8)254, light_LUT[i - 1]) + 1; + } } } |