diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2020-11-23 18:26:54 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2020-11-25 22:31:47 +0300 |
commit | 02a0f6b04a648b62150a310e67628efc1c0773e8 (patch) | |
tree | c28a8cd2636c2b8d6c9aaec444af62f238ba0b04 /source/blender/blenkernel/intern/particle_system.c | |
parent | 8330e19cb2e7faca9884e34a8f46564250c8c29a (diff) |
Fluid Particles: fix viscoelastic spring threading crash again after D7394.
Since D6133 fluid particle code uses thread local storage to collect
springs created during a time step before adding them to the actual
spring array.
Prior to the switch to TBB there was a single finalize callback which
was called on the main thread, so it could use psys_sph_flush_springs
and insert the new entries into the final buffer. However in D7394 it
was replaced with a reduce callback, which is supposed to be thread
safe and have no side effects. This means that the only thing it can
safely do is copy entries to the other temporary buffer.
In addition, careful checking reveals that the 'classical' solver
doesn't actually add springs, so reduce isn't needed there.
Differential Revision: https://developer.blender.org/D9632
Diffstat (limited to 'source/blender/blenkernel/intern/particle_system.c')
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 35ff387c9a6..35265cf8b68 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -3694,12 +3694,20 @@ typedef struct DynamicStepSolverTaskData { } DynamicStepSolverTaskData; static void dynamics_step_sphdata_reduce(const void *__restrict UNUSED(userdata), - void *__restrict UNUSED(join_v), + void *__restrict join_v, void *__restrict chunk_v) { - SPHData *sphdata = chunk_v; + SPHData *sphdata_to = join_v; + SPHData *sphdata_from = chunk_v; - psys_sph_flush_springs(sphdata); + if (sphdata_from->new_springs.count > 0) { + BLI_buffer_append_array(&sphdata_to->new_springs, + ParticleSpring, + &BLI_buffer_at(&sphdata_from->new_springs, ParticleSpring, 0), + sphdata_from->new_springs.count); + } + + BLI_buffer_field_free(&sphdata_from->new_springs); } static void dynamics_step_sph_ddr_task_cb_ex(void *__restrict userdata, @@ -4020,7 +4028,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) settings.use_threading = (psys->totpart > 100); settings.userdata_chunk = &sphdata; settings.userdata_chunk_size = sizeof(sphdata); - settings.func_reduce = dynamics_step_sphdata_reduce; BLI_task_parallel_range(0, psys->totpart, &task_data, @@ -4035,7 +4042,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) settings.use_threading = (psys->totpart > 100); settings.userdata_chunk = &sphdata; settings.userdata_chunk_size = sizeof(sphdata); - settings.func_reduce = dynamics_step_sphdata_reduce; BLI_task_parallel_range(0, psys->totpart, &task_data, |