[Bf-blender-cvs] [317a5f61f00] master: Cycles: Fix recently introduced off-by-one error in an assert

Lukas Stockner noreply at git.blender.org
Tue Jan 10 02:21:04 CET 2023


Commit: 317a5f61f00b06dfbd2b5140149e588db36b3c60
Author: Lukas Stockner
Date:   Tue Jan 10 02:07:00 2023 +0100
Branches: master
https://developer.blender.org/rB317a5f61f00b06dfbd2b5140149e588db36b3c60

Cycles: Fix recently introduced off-by-one error in an assert

This was added in rB95696d09bc07, but I got the index wrong.

===================================================================

M	intern/cycles/util/math_cdf.cpp

===================================================================

diff --git a/intern/cycles/util/math_cdf.cpp b/intern/cycles/util/math_cdf.cpp
index a009652d8c8..cc02d630977 100644
--- a/intern/cycles/util/math_cdf.cpp
+++ b/intern/cycles/util/math_cdf.cpp
@@ -16,7 +16,9 @@ void util_cdf_invert(const int resolution,
                      const bool make_symmetric,
                      vector<float> &inv_cdf)
 {
-  assert(cdf[0] == 0.0f && cdf[resolution] == 1.0f);
+  const int cdf_size = cdf.size();
+  assert(cdf[0] == 0.0f && cdf[cdf_size - 1] == 1.0f);
+
   const float inv_resolution = 1.0f / (float)resolution;
   const float range = to - from;
   inv_cdf.resize(resolution);
@@ -26,12 +28,12 @@ void util_cdf_invert(const int resolution,
       float x = i / (float)half_size;
       int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin();
       float t;
-      if (index < cdf.size() - 1) {
+      if (index < cdf_size - 1) {
         t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
       }
       else {
         t = 0.0f;
-        index = cdf.size() - 1;
+        index = cdf_size - 1;
       }
       float y = ((index + t) / (resolution - 1)) * (2.0f * range);
       inv_cdf[half_size + i] = 0.5f * (1.0f + y);
@@ -43,7 +45,7 @@ void util_cdf_invert(const int resolution,
       float x = (i + 0.5f) * inv_resolution;
       int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin() - 1;
       float t;
-      if (index < cdf.size() - 1) {
+      if (index < cdf_size - 1) {
         t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
       }
       else {



More information about the Bf-blender-cvs mailing list