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.
This commit is contained in:
Alexander Gavrilov 2016-09-05 15:50:12 +03:00
parent c51cfbbc7f
commit a31eca3fdd
Notes: blender-bot 2023-02-14 07:38:30 +01:00
Referenced by issue #49251, Moving smoke domain when additional resolution is increased causes blender to crash
1 changed files with 3 additions and 2 deletions

View File

@ -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);