From 051b02ed115d31bdc26a5a9b526e07210a21ca4a Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 20 Oct 2023 16:47:15 +0200 Subject: [PATCH] Fix #113851: viscoelastic springs do not work Caused by 425b871607. The root issue was that these two states of the hash table were mixed up in 425b871607: (1) the hash table exists and (2) the hash table is empty. The use of `std::optional` restores these two different states again. --- source/blender/blenkernel/BKE_particle.h | 4 +++- source/blender/blenkernel/intern/particle_system.cc | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 8be441d047e..15b353aeab6 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -9,6 +9,8 @@ * \ingroup bke */ +#include + #include "BLI_buffer.h" #include "BLI_compiler_attrs.h" #include "BLI_map.hh" @@ -85,7 +87,7 @@ typedef struct SPHData { ParticleSystem *psys[10]; ParticleData *pa; float mass; - blender::Map eh; + std::optional> eh; float *gravity; float hfac; /* Average distance to neighbors (other particles in the support domain), diff --git a/source/blender/blenkernel/intern/particle_system.cc b/source/blender/blenkernel/intern/particle_system.cc index a7b8172a0d8..ca26b6a1cbd 100644 --- a/source/blender/blenkernel/intern/particle_system.cc +++ b/source/blender/blenkernel/intern/particle_system.cc @@ -1806,7 +1806,7 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa SPHRangeData pfr; SPHNeighbor *pfn; float *gravity = sphdata->gravity; - const blender::Map &springhash = sphdata->eh; + const std::optional> &springhash = sphdata->eh; float q, u, rij, dv[3]; float pressure, near_pressure; @@ -1890,9 +1890,9 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa if (spring_constant > 0.0f) { /* Viscoelastic spring force */ - if (pfn->psys == psys[0] && fluid->flag & SPH_VISCOELASTIC_SPRINGS && !springhash.is_empty()) + if (pfn->psys == psys[0] && fluid->flag & SPH_VISCOELASTIC_SPRINGS && springhash.has_value()) { - spring_index = springhash.lookup({index, pfn->index}); + spring_index = springhash->lookup_default({index, pfn->index}, 0); if (spring_index) { spring = psys[0]->fluid_springs + spring_index - 1;