From 046adde64f164e5dec2721abbc89bb7759979f92 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 16 Jun 2016 14:05:53 +0200 Subject: 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. --- source/blender/blenkernel/intern/particle_distribute.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index 0d7fe04a1e4..7830e4eb650 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -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; } } -- cgit v1.2.3