From fd090aee59f07b93d3bbba3b57566c36b0eb61b3 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Fri, 12 Jan 2024 15:04:00 +0100 Subject: [PATCH] Fix #106425: Mantaflow guiding with domains is broken Caused by e968b4197b / 67e23b4b29 Since culprit commits, we are not running `MANTA::initGuiding` / `fluid_alloc_guiding` if guiding is meant to be pulled from other domains (it does work with effectors though). This is because atm. only the `FLUID_DOMAIN_ACTIVE_GUIDE` flag sets `mUsingGuiding` to true (activated in `update_obstacleflags`, so only for effectors). So to fix this, we have to ensure that `MANTA::initGuiding` runs (also if guiding is pulled from domains), but also make sure we dont run into the crashes from T102257. It seems that the real reason we were getting crashes in T102257 is that 67e23b4b29 made it so that resetting the cache (including a call to `fluid_modifier_reset_ex`) in `fluid_modifier_processDomain` happens **after** `FluidDomainSettings.active_fields` have been updated (this happens in `update_flowsflags` & `update_obstacleflags`). But `fluid_modifier_reset_ex` also resets `FluidDomainSettings.active_fields`. If we then update pointers later in `fluid_modifier_processDomain`, we never get anything in the guiding related pointers for the new `mCurrentID` (specifically `mPhiGuideIn` will be a nullptr). This is the real reason `initGuiding()` runs a second time (it does once for `fluid_modifier_init` then again as a consequence of the call to `manta_guiding`). This patch proposes to move the resetting process from 67e23b4b29 **above** the refreshing of the `FluidDomainSettings.active_fields`, this way these field stay intact, we do get the first run of `initGuiding()` from `fluid_modifier_init`, manta pointers get updated with intact fields afterwards (so we then get a valid `mPhiGuideIn`), which then prevents the second run from `manta_guiding` to actually call the python script again. The fix from e968b4197b is then not needed and reverted in this patch. This should be good for LTS I think. --- intern/mantaflow/intern/MANTA_main.cpp | 2 +- source/blender/blenkernel/intern/fluid.cc | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp index 2833f6946e4..b9552c82335 100644 --- a/intern/mantaflow/intern/MANTA_main.cpp +++ b/intern/mantaflow/intern/MANTA_main.cpp @@ -60,6 +60,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) mUsingDiffusion = (fds->flags & FLUID_DOMAIN_USE_DIFFUSION) && mUsingLiquid; mUsingViscosity = (fds->flags & FLUID_DOMAIN_USE_VISCOSITY) && mUsingLiquid; mUsingMVel = (fds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS) && mUsingLiquid; + mUsingGuiding = (fds->flags & FLUID_DOMAIN_USE_GUIDE); mUsingDrops = (fds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY) && mUsingLiquid; mUsingBubbles = (fds->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE) && mUsingLiquid; mUsingFloats = (fds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM) && mUsingLiquid; @@ -69,7 +70,6 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) mUsingFire = (fds->active_fields & FLUID_DOMAIN_ACTIVE_FIRE) && mUsingSmoke; mUsingColors = (fds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS) && mUsingSmoke; mUsingObstacle = (fds->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE); - mUsingGuiding = (fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE); mUsingInvel = (fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL); mUsingOutflow = (fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW); diff --git a/source/blender/blenkernel/intern/fluid.cc b/source/blender/blenkernel/intern/fluid.cc index 0811de98e5d..4620dcb7f4d 100644 --- a/source/blender/blenkernel/intern/fluid.cc +++ b/source/blender/blenkernel/intern/fluid.cc @@ -3721,6 +3721,17 @@ static void fluid_modifier_processDomain(FluidModifierData *fmd, const char *relbase = BKE_modifier_path_relbase_from_global(ob); BLI_path_abs(fds->cache_directory, relbase); + /* If 'outdated', reset the cache here. */ + if (is_startframe && mode == FLUID_DOMAIN_CACHE_REPLAY) { + PTCacheID pid; + BKE_ptcache_id_from_smoke(&pid, ob, fmd); + if (pid.cache->flag & PTCACHE_OUTDATED) { + BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); + BKE_fluid_cache_free_all(fds, ob); + fluid_modifier_reset_ex(fmd, false); + } + } + /* Ensure that all flags are up to date before doing any baking and/or cache reading. */ objs = BKE_collision_objects_create( depsgraph, ob, fds->fluid_group, &numobj, eModifierType_Fluid); @@ -3735,17 +3746,6 @@ static void fluid_modifier_processDomain(FluidModifierData *fmd, MEM_freeN(objs); } - /* If 'outdated', reset the cache here. */ - if (is_startframe && mode == FLUID_DOMAIN_CACHE_REPLAY) { - PTCacheID pid; - BKE_ptcache_id_from_smoke(&pid, ob, fmd); - if (pid.cache->flag & PTCACHE_OUTDATED) { - BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); - BKE_fluid_cache_free_all(fds, ob); - fluid_modifier_reset_ex(fmd, false); - } - } - /* Fluid domain init must not fail in order to continue modifier evaluation. */ if (!fds->fluid && !fluid_modifier_init(fmd, depsgraph, ob, scene, mesh)) { CLOG_ERROR(&LOG, "Fluid initialization failed. Should not happen!"); -- 2.30.2