From a31eca3fdd0d2e18b73f180b87a4c77ac5a8da78 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 5 Sep 2016 15:50:12 +0300 Subject: Fix T49251: moving smoke domain with additional resolution causes crash. This is a bug in the multithreaded task manager in negative value range. The problem here is that if previter is unsigned, the comparison in the return statement is unsigned, and works incorrectly if stop < 0 && iter >= 0. This in turn can happen if stop is close to 0, because this code is designed to overrun the stop by chunk_size*num_threads as the threads terminate. This probably should go into 2.78 as it prevents a crash. --- source/blender/blenlib/intern/task.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/blenlib/intern/task.c') diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index bd7b7f9cdbd..9d4d40e1eae 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -780,9 +780,10 @@ BLI_INLINE bool parallel_range_next_iter_get( ParallelRangeState * __restrict state, int * __restrict iter, int * __restrict count) { - uint32_t previter = atomic_fetch_and_add_uint32((uint32_t *)(&state->iter), state->chunk_size); + uint32_t uval = atomic_fetch_and_add_uint32((uint32_t *)(&state->iter), state->chunk_size); + int previter = *(int32_t*)&uval; - *iter = (int)previter; + *iter = previter; *count = max_ii(0, min_ii(state->chunk_size, state->stop - previter)); return (previter < state->stop); -- cgit v1.2.3