Fix #68436: External Particle Disk Cache Playback Is Broken #117401

Merged
Philipp Oeser merged 2 commits from lichtwerk/blender:68436_b into main 2024-01-23 09:37:52 +01:00
1 changed files with 30 additions and 2 deletions

View File

@ -61,6 +61,8 @@
#include "BLO_read_write.hh"
#include "DEG_depsgraph_query.hh"
#include "BIK_api.h"
#ifdef WITH_BULLET
@ -3355,7 +3357,20 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
cache->flag |= PTCACHE_BAKED;
/* write info file */
if (cache->flag & PTCACHE_DISK_CACHE) {
BKE_ptcache_write(pid, 0);
if (pid->type == PTCACHE_TYPE_PARTICLES) {
/* Since writing this from outside the bake job, make sure the ParticleSystem and
* PTCacheID is in a fully evaluated state. */
PTCacheID pid_eval;
Object *ob = reinterpret_cast<Object *>(pid->owner_id);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
lichtwerk marked this conversation as resolved

Don't check GS(id->name) == ID_OB. If that fails the rest of the code here crashes anyway.

Don't check `GS(id->name) == ID_OB`. If that fails the rest of the code here crashes anyway.
ParticleSystem *psys = static_cast<ParticleSystem *>(pid->calldata);
ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys);
BKE_ptcache_id_from_particles(&pid_eval, ob_eval, psys_eval);
BKE_ptcache_write(&pid_eval, 0);
}
else {
BKE_ptcache_write(pid, 0);
}
}
}
}
@ -3385,7 +3400,20 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
if (bake) {
cache->flag |= PTCACHE_BAKED;
if (cache->flag & PTCACHE_DISK_CACHE) {
BKE_ptcache_write(pid, 0);
if (pid->type == PTCACHE_TYPE_PARTICLES) {
/* Since writing this from outside the bake job, make sure the ParticleSystem and
* PTCacheID is in a fully evaluated state. */
PTCacheID pid_eval;
Object *ob = reinterpret_cast<Object *>(pid->owner_id);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
ParticleSystem *psys = static_cast<ParticleSystem *>(pid->calldata);
ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys);
BKE_ptcache_id_from_particles(&pid_eval, ob_eval, psys_eval);
BKE_ptcache_write(&pid_eval, 0);
}
else {
BKE_ptcache_write(pid, 0);
}
}
}
}