Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2020-12-11 20:12:29 +0300
committerJeroen Bakker <jeroen@blender.org>2021-01-13 11:24:13 +0300
commit350d490a1328536447ec11d2461e4d30546ee8a0 (patch)
treeef05143957a4bb95b1e9aaeca00786069e70f96f
parent02ff143f60977c2175b86fddb649a8c4c7787f84 (diff)
Fix T83280: Crash when deleting hair collision collection.
Root of the issue was missing management of ID pointers in the cloth modifier data stored in ParticleSystem for hair physics, in the 'foreach_id' particle system code. Using modifier's 'foreach_id' code in psys one unfortunately requires some ugly conversion gymnastics, but this is still better than having dedicated code for that case. Note that this is actually a fairly critical issue, fix should be backported to 2.91.1 should we do it, and to 2.83 LTS as well I think.
-rw-r--r--source/blender/blenkernel/intern/particle_system.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index f7400264131..b3472bfe716 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -4190,7 +4190,7 @@ static void particles_fluid_step(ParticleSimulationData *sim,
ParticleSettings *part = psys->part;
ParticleData *pa = NULL;
- int p, totpart, tottypepart = 0;
+ int p, totpart = 0, tottypepart = 0;
int flagActivePart, activeParts = 0;
float posX, posY, posZ, velX, velY, velZ;
float resX, resY, resZ;
@@ -4971,6 +4971,24 @@ void particle_system_update(struct Depsgraph *depsgraph,
/* ID looper */
+/* unfortunately PSys and modifier ID loopers are not directly compatible, so we need this struct
+ * and the callback below to map the former to the latter (thanks to psys embedding a Cloth
+ * modifier data struct now, for Hair physics simulations). */
+typedef struct ParticleSystemIDLoopForModifier {
+ ParticleSystem *psys;
+ ParticleSystemIDFunc func;
+ void *userdata;
+} ParticleSystemIDLoopForModifier;
+
+static void particlesystem_modifiersForeachIDLink(void *user_data,
+ Object *UNUSED(object),
+ ID **id_pointer,
+ int cb_flag)
+{
+ ParticleSystemIDLoopForModifier *data = (ParticleSystemIDLoopForModifier *)user_data;
+ data->func(data->psys, id_pointer, data->userdata, cb_flag);
+}
+
void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata)
{
ParticleTarget *pt;
@@ -4979,6 +4997,16 @@ void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func,
func(psys, (ID **)&psys->target_ob, userdata, IDWALK_CB_NOP);
func(psys, (ID **)&psys->parent, userdata, IDWALK_CB_NOP);
+ if (psys->clmd != NULL) {
+ const ModifierTypeInfo *mti = modifierType_getInfo(psys->clmd->modifier.type);
+
+ if (mti->foreachIDLink != NULL) {
+ ParticleSystemIDLoopForModifier data = {.psys = psys, .func = func, .userdata = userdata};
+ mti->foreachIDLink(
+ &psys->clmd->modifier, NULL, particlesystem_modifiersForeachIDLink, &data);
+ }
+ }
+
for (pt = psys->targets.first; pt; pt = pt->next) {
func(psys, (ID **)&pt->ob, userdata, IDWALK_CB_NOP);
}