[Bf-blender-cvs] [046adde] master: Fix some rare asserts with new simple/random particle distribution code.

Bastien Montagne noreply at git.blender.org
Thu Jun 16 14:09:27 CEST 2016


Commit: 046adde64f164e5dec2721abbc89bb7759979f92
Author: Bastien Montagne
Date:   Thu Jun 16 14:05:53 2016 +0200
Branches: master
https://developer.blender.org/rB046adde64f164e5dec2721abbc89bb7759979f92

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.

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

M	source/blender/blenkernel/intern/particle_distribute.c

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

diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index 0d7fe04..7830e4e 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;
 		}
 	}




More information about the Bf-blender-cvs mailing list