Fix some rare asserts with new simple/random particle distribution code.

Optimization in binary search could lead to equality instead of expected strictly greater than value.
Harmless but noisy, and better be strict here.

reported by sergey on irc (with koro cycles benchmark file), thanks.
This commit is contained in:
Bastien Montagne 2016-06-16 14:05:53 +02:00
parent 5ea27bec1f
commit 046adde64f
Notes: blender-bot 2023-02-14 11:21:43 +01:00
Referenced by commit 61b49de449, Fix once more time particle distribution.
1 changed files with 4 additions and 3 deletions

View File

@ -408,10 +408,10 @@ static int distribute_binary_search(float *sum, int n, float value)
return mid;
if (sum[mid] > value) {
high = mid - 1;
high = mid;
}
else {
low = mid + 1;
low = mid;
}
}
@ -1056,7 +1056,8 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
const float pos = BLI_frand() * element_sum[totmapped - 1];
const int eidx = distribute_binary_search(element_sum, totmapped, pos);
particle_element[p] = element_map[eidx];
BLI_assert(pos <= element_sum[eidx] && pos > (eidx ? element_sum[eidx - 1] : 0.0f));
BLI_assert(pos <= element_sum[eidx]);
BLI_assert(eidx ? (pos > element_sum[eidx - 1]) : (pos >= 0.0f));
jitter_offset[particle_element[p]] = pos;
}
}