Skip to content

Commit

Permalink
Fix light overflow of u8 if light is saturated at 255 (#10305)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminRi committed Aug 23, 2020
1 parent cf55472 commit f5a203f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/light.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit f5a203f

Please sign in to comment.